Skip to content

非公式 / UnofficialCloudflare, Inc. 非提携。アカウント情報は入力しないでください。Not affiliated with Cloudflare, Inc. Do not enter Cloudflare credentials here.Official docsこのサイトについてプライバシー

Python Workflows SDK

最終更新 Markdown で表示Agent セットアップ

Workflow のエントリポイントは Python で宣言できます。Cloudflare Workers プラットフォーム上で動く WorkflowEntrypoint をエクスポートします。 Workers ランタイム上の Python については Python Workers を参照してください。

始める

Python Workflow の主なエントリポイントは WorkflowEntrypoint クラスです。Workflow のロジックは run ハンドラー内に置きます。

from workers import WorkflowEntrypoint

class MyWorkflow(WorkflowEntrypoint):
    async def run(self, event, step):
        # steps here

たとえば、Workflow は次のように定義できます。

from workers import Response, WorkflowEntrypoint, WorkerEntrypoint

class PythonWorkflowStarter(WorkflowEntrypoint):
    async def run(self, event, step):

        @step.do('step1')
        async def step_1():
            # does stuff
            print('executing step1')

        @step.do('step2')
        async def step_2():
            # does stuff
            print('executing step2')

        await step_1()
        await step_2()

class Default(WorkerEntrypoint):
    async def fetch(self, request):
        await self.env.MY_WORKFLOW.create()
        return Response("Hello world!")

Wrangler 設定ファイルに python_workflows と python_workers の両方の compatibility flag を追加する必要があります。

{
	"$schema": "./node_modules/wrangler/config-schema.json",
	"name": "hello-python",
	"main": "src/entry.py",
	"compatibility_flags": [
		"python_workers",
		"python_workflows"
	],
	// Set this to today's date
	"compatibility_date": "2026-11-14",
	"workflows": [
		{
			"name": "workflows-demo",
			"binding": "MY_WORKFLOW",
			"class_name": "PythonWorkflowStarter"
		}
	]
}
"$schema" = "./node_modules/wrangler/config-schema.json"
name = "hello-python"
main = "src/entry.py"
compatibility_flags = [ "python_workers", "python_workflows" ]
# Set this to today's date
compatibility_date = "2026-11-14"

[[workflows]]
name = "workflows-demo"
binding = "MY_WORKFLOW"
class_name = "PythonWorkflowStarter"

Python Workflow をローカルで実行するには、Cloudflare Workers 向け CLI の Wrangler を使います。

npx wrangler@latest dev

Python Workflow を Cloudflare にデプロイするには、wrangler deploy を実行します。

npx wrangler@latest deploy

Cloudflare Developers Discord ↗ の #python-workers チャンネルに参加し、次に見てほしい内容を教えてください。

役に立ちましたか?