
Cloudflare Workflows, previously TypeScript-only, now accepts Python. The runtime runs Python Workers natively, so the Python SDK exposes the same orchestration APIs the JavaScript SDK does — idempotent steps, error handling and retries — with essentially full feature parity between the two.
The gap it fills is real: data pipelines, AI/ML training, and task automation are all orchestration-heavy and overwhelmingly written in Python on Cloudflare. Python has been on Workers since the 2020 Transcrypt release, was built directly into workerd in 2024, and earlier this year gained CPython support plus Pyodide-built packages such as matplotlib and pandas.
Where it fits
A model-training loop is the canonical case: label the dataset, feed data, wait for the run, evaluate the loss, adjust. Done by hand, every stage turns into manual monitoring before the next can start; a workflow triggers each step only after its predecessor completes, and inserts a step that notifies a human and blocks until input arrives whenever a manual adjustment is required.
For autonomous agents it plays out the same way. An agent that assembles a weekly grocery order might: await step.wait_for_event() for the user's recipe list, step.do() to compile required ingredients, step.do() to diff against leftovers, step.do() to call the ordering API, and step.do() to pay. Per-step retries and persisted state mean the agent's architecture can stay simple and still reliably reach completion.
How the pieces connect
Workflows is built on Workers and Durable Objects, which store both workflow metadata and per-instance data. The user's Worker — the WorkflowEntrypoint — sits at the bottom of the control plane; once an instance is ready, the engine makes an RPC call into its run method. The skeleton from the docs:
export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
async run(event: WorkflowEvent<Params>, step: WorkflowStep) {
// Steps here
}
}The WorkflowStep argument carries the durable-execution APIs that give at-most-once semantics. Those APIs are implemented in JavaScript, so the engine exposes the step object as an RpcTarget across the RPC boundary; the callee substitutes a stub and reaches the engine's APIs by RPC — the same mechanism described in the Workers RPC documentation. None of this differs between the two languages.
The JavaScript-to-Python bridge
For a Python Worker, an RPC request first lands in a JavaScript entrypoint module that proxies it to the Python code and returns the result, translating types in both directions. Python Workers run on Pyodide, the CPython-to-WebAssembly port whose FFI is the channel for calling JavaScript from Python — and what underpins other bindings and packages on the platform.
That FFI layer is also how WorkflowStep methods reach Python. The runtime treats WorkflowEntrypoint as a special class and manually wraps its run method so WorkflowStep arrives as a JsProxy rather than being type-translated like ordinary JavaScript objects. Wrapping at the user-Worker level also lets the SDK adjust the developer experience instead of transplanting JavaScript semantics into a language that behaves differently.
Making the SDK idiomatic
Python lacks convenient anonymous callbacks, so the port reworks how the do method receives its callback. The TypeScript version looks like this:
import { WorkflowEntrypoint, WorkflowStep, WorkflowEvent} from 'cloudflare:workers';
export class MyWorkflow extends WorkflowEntrypoint {
async run(event: WorkflowEvent<YourEventType>, step: WorkflowStep) {
let state = step.do("my first step", async () => {
// Access your properties via event.payload
let userEmail = event.payload.userEmail
let createdTimestamp = event.payload.createdTimestamp
return {"userEmail": userEmail, "createdTimestamp": createdTimestamp}
})
step.sleep("my first sleep", "30 minutes");
await step.waitForEvent<EventType>("receive example event", { type: "simple-event", timeout: "1 hour" })
const developerWeek = Date.parse("22 Sept 2025 13:00:00 UTC");
await step.sleepUntil("sleep until X times out", developerWeek)
}
}In Python, a decorator does the interception, leaving every parameter in its original position with the decorated method acting as the callback. waitForEvent, sleep and sleepUntil keep their signatures, renamed to snake case. The Python spelling of the same workflow:
from workers import WorkflowEntrypoint
class MyWorkflow(WorkflowEntrypoint):
async def run(self, event, step):
@step.do("my first step")
async def my_first_step():
user_email = event["payload"]["userEmail"]
created_timestamp = event["payload"]["createdTimestamp"]
return {
"userEmail": user_email,
"createdTimestamp": created_timestamp,
}
await my_first_step()
step.sleep("my first sleep", "30 minutes")
await step.wait_for_event(
"receive example event",
"simple-event",
timeout="1 hour",
)
developer_week = datetime(2024, 10, 24, 13, 0, 0, tzinfo=timezone.utc)
await step.sleep_until("sleep until X times out", developer_week)Concurrency and declarative DAGs
Many workflows are really directed acyclic graphs, with step dependencies alongside tasks that could run together. Pyodide's handling of JavaScript thenables — captured and proxied as Python awaitables — already allows this, so asyncio.gather serves as the counterpart of Promise.all. On top of that, the SDK offers a declarative form:
from workers import Response, WorkflowEntrypoint
class PythonWorkflowDAG(WorkflowEntrypoint):
async def run(self, event, step):
@step.do('dependency 1')
async def dep_1():
# does stuff
print('executing dep1')
@step.do('dependency 2')
async def dep_2():
# does stuff
print('executing dep2')
@step.do('demo do', depends=[dep_1, dep_2], concurrent=True)
async def final_step(res1=None, res2=None):
# does stuff
print('something')
await final_step()Because do is decorated, the SDK can layer abstractions over the base API that resolve inside the entrypoint wrapper, leaving state management to the engine's data plane and the Python Worker wrapper. Reused step names are permitted: the engine discreetly adjusts each one to keep it unique. A dependency counts as resolved once the first step that involves it succeeds.
Getting started: the docs cover writing Workers in Python and creating a first Python Workflow, and the Cloudflare Developers Discord takes bug reports and feature requests.



