|
| 1 | +--- |
| 2 | +title: Build durable multi-step applications in Python with Workflows (now in beta) |
| 3 | +description: Python Workflows is now open beta - build Workflows in Python. |
| 4 | +products: |
| 5 | + - workflows |
| 6 | + - workers |
| 7 | +date: 2025-08-22 |
| 8 | +--- |
| 9 | + |
| 10 | +import { Render, PackageManagers, TypeScriptExample } from "~/components" |
| 11 | + |
| 12 | +You can now build [Workflows](/workflows/) using Python. With Python Workflows, you get automatic retries, state persistence, and the ability to run multi-step operations that can span minutes, hours, or weeks using Python’s familiar syntax and the [Python Workers](/workers/languages/python/) runtime. |
| 13 | + |
| 14 | +Python Workflows use the same step-based execution model as JavaScript Workflows, but with Python syntax and access to Python’s ecosystem. Python Workflows also enable [DAG (Directed Acyclic Graph) workflows](/workflows/python/dag/), where you can define complex dependencies between steps using the depends parameter. |
| 15 | + |
| 16 | +Here’s a simple example: |
| 17 | + |
| 18 | +```python |
| 19 | +from workers import Response, WorkflowEntrypoint |
| 20 | + |
| 21 | +class PythonWorkflowStarter(WorkflowEntrypoint): |
| 22 | + async def run(self, event, step): |
| 23 | + @step.do("my first step") |
| 24 | + async def my_first_step(): |
| 25 | + # do some work |
| 26 | + return "Hello Python!" |
| 27 | + |
| 28 | + await my_first_step() |
| 29 | + |
| 30 | + await step.sleep("my-sleep-step", "10 seconds") |
| 31 | + |
| 32 | + @step.do("my second step") |
| 33 | + async def my_second_step(): |
| 34 | + # do some more work |
| 35 | + return "Hello again!" |
| 36 | + |
| 37 | + await my_second_step() |
| 38 | + |
| 39 | +async def on_fetch(request, env): |
| 40 | + await env.MY_WORKFLOW.create() |
| 41 | + return Response("Hello Workflow creation!") |
| 42 | +``` |
| 43 | + |
| 44 | +:::note |
| 45 | +Python Workflows requires a `compatibility_date = "2025-08-01"`, or lower, in your wrangler toml file. |
| 46 | +::: |
| 47 | + |
| 48 | +Python Workflows support the same core capabilities as JavaScript Workflows, including sleep scheduling, event-driven workflows, and built-in error handling with configurable retry policies. |
| 49 | + |
| 50 | +To learn more and get started, refer to [Python Workflows documentation](/workflows/python/). |
0 commit comments