Python Workflows SDK
Workflow entrypoints can be declared using Python. To achieve this, you can export a WorkflowEntrypoint that runs on the Cloudflare Workers platform.
Refer to Python Workers for more information about Python on the Workers runtime.
The main entrypoint for a Python workflow is the WorkflowEntrypoint class. Your workflow logic should exist inside the run handler.
from workers import WorkflowEntrypoint
class MyWorkflow(WorkflowEntrypoint): async def run(self, event, step): # steps hereFor example, a Workflow may be defined as:
from workers import Response, WorkflowEntrypoint
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 await_step(step_1,step_2)
async def on_fetch(request, env): await env.MY_WORKFLOW.create() return Response("Hello world!")You must add both python_workflows and python_workers compatibility flags to your wrangler.toml file.
{ "$schema": "./node_modules/wrangler/config-schema.json", "name": "hello-python", "main": "src/entry.py", "compatibility_flags": [ "python_workers", "experimental", "python_workflows" ], "compatibility_date": "2024-03-29", "workflows": [ { "name": "workflows-demo", "binding": "MY_WORKFLOW", "class_name": "PythonWorkflowStarter" } ]}name = "hello-python"main = "src/entry.py"compatibility_flags = ["python_workers", "experimental", "python_workflows"]compatibility_date = "2024-03-29"
[[workflows]]name = "workflows-demo"binding = "MY_WORKFLOW"class_name = "PythonWorkflowStarter"To run a Python Workflow locally, use Wrangler, the CLI for Cloudflare Workers:
npx wrangler@latest devTo deploy a Python Workflow to Cloudflare, run wrangler deploy:
npx wrangler@latest deployJoin the #python-workers channel in the Cloudflare Developers Discord ↗ and let us know what you would like to see next.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-