diff --git a/src/content/docs/workflows/python/index.mdx b/src/content/docs/workflows/python/index.mdx index ee5964030e494a7..370eee5ad48b2aa 100644 --- a/src/content/docs/workflows/python/index.mdx +++ b/src/content/docs/workflows/python/index.mdx @@ -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. @@ -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 @@ -42,4 +72,6 @@ To deploy a Python Workflow to Cloudflare, run [`wrangler deploy`](/workers/wran ```bash npx wrangler@latest deploy -``` \ No newline at end of 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. \ No newline at end of file diff --git a/src/content/docs/workflows/python/python-workers-api.mdx b/src/content/docs/workflows/python/python-workers-api.mdx index 67b4daa3557e89e..7e63d5ce06f8720 100644 --- a/src/content/docs/workflows/python/python-workers-api.mdx +++ b/src/content/docs/workflows/python/python-workers-api.mdx @@ -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. * step.sleep(name, duration)