Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 42 additions & 10 deletions src/content/docs/workflows/python/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ sidebar:
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](/workers/languages/python) for more information about Python on the Workers runtime.

:::caution[Python Workflows are in beta, as well as the underlying platform.]

You must add both `python_workflows` and `python_workers` compatibility flags to your `wrangler.toml` file.

Also, Python Workflows requires `compatibility_date = "2025-08-01"`, or lower, to be set in your `wrangler.toml` file.

Join the #python-workers channel in the [Cloudflare Developers Discord](https://discord.cloudflare.com/) and let us know what you'd like to see next.
:::

## Get Started

The main entrypoint for a Python workflow is the [`WorkflowEntrypoint`](/workflows/build/workers-api/#workflowentrypoint) class. Your workflow logic should exist inside the [`run`](/workflows/build/workers-api/#run) handler.
Expand All @@ -32,6 +23,45 @@ class MyWorkflow(WorkflowEntrypoint):
# steps here
```

For example, a Workflow may be defined as:

```python
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. Also, Python Workflows requires `compatibility_date = "2025-08-01"`, or lower, to be set in your `wrangler.toml` file.

```
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, you use [Wrangler](/workers/wrangler/), the CLI for Cloudflare Workers:

```bash
Expand All @@ -42,4 +72,6 @@ To deploy a Python Workflow to Cloudflare, run [`wrangler deploy`](/workers/wran

```bash
npx wrangler@latest deploy
```
```

Join the #python-workers channel in the [Cloudflare Developers Discord](https://discord.cloudflare.com/) and let us know what you'd like to see next.
2 changes: 1 addition & 1 deletion src/content/docs/workflows/python/python-workers-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class MyWorkflow(WorkflowEntrypoint):

Note that the decorator doesn't make the call to the step, it just returns a callable that can be used to invoke the step. You have to call the callable to make the step run.

When returning state from a step, you must make sure that the returned value is serializable. Since steps run through an FFI layer, the returned value gets type translated via [FFI.](https://pyodide.org/en/stable/usage/api/python-api/ffi.html#pyodide.ffi.to_js)
When returning state from a step, you must make sure that the returned value is serializable. Since steps run through an [FFI](/workers/languages/python/ffi/) layer, the returned value gets type translated via [FFI.](https://pyodide.org/en/stable/usage/api/python-api/ffi.html#pyodide.ffi.to_js)
Refer to [Pyodide's documentation](https://pyodide.org/en/stable/usage/type-conversions.html#type-translations-pyproxy-to-js) regarding type conversions for more information.

* <code>step.sleep(name, duration)</code>
Expand Down