Skip to content

Commit 5e83d1d

Browse files
authored
Replace remaining examples with on_fetch with WorkerEntrypoint class (#25794)
1 parent 1ee6b5e commit 5e83d1d

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/content/changelog/workflows/2025-08-22-workflows-python-beta.mdx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ products:
77
date: 2025-08-22
88
---
99

10-
import { Render, PackageManagers, TypeScriptExample } from "~/components"
10+
import { Render, PackageManagers, TypeScriptExample } from "~/components";
1111

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.
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.
1313

1414
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.
1515

@@ -36,9 +36,10 @@ class PythonWorkflowStarter(WorkflowEntrypoint):
3636

3737
await my_second_step()
3838

39-
async def on_fetch(request, env):
40-
await env.MY_WORKFLOW.create()
41-
return Response("Hello Workflow creation!")
39+
class Default(WorkerEntrypoint):
40+
async def fetch(self, request):
41+
await self.env.MY_WORKFLOW.create()
42+
return Response("Hello Workflow creation!")
4243
```
4344

4445
:::note
@@ -47,4 +48,4 @@ Python Workflows requires a `compatibility_date = "2025-08-01"`, or lower, in yo
4748

4849
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.
4950

50-
To learn more and get started, refer to [Python Workflows documentation](/workflows/python/).
51+
To learn more and get started, refer to [Python Workflows documentation](/workflows/python/).

src/content/docs/workflows/python/bindings.mdx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,17 @@ Create (trigger) a new instance of a given Workflow.
7171
type.
7272

7373
```python
74-
from pyodide.ffi import to_js
7574
from js import Object
75+
from pyodide.ffi import to_js
76+
from workers import WorkerEntrypoint, Response
77+
7678

77-
async def on_fetch(request, env, ctx):
78-
event = {"foo": "bar"}
79-
options = to_js({"params": event}, dict_converter=Object.fromEntries)
80-
await env.MY_WORKFLOW.create(options)
81-
return Response.json({"status": "success"})
79+
class Default(WorkerEntrypoint):
80+
async def fetch(self, request):
81+
event = {"foo": "bar"}
82+
options = to_js({"params": event}, dict_converter=Object.fromEntries)
83+
await self.env.MY_WORKFLOW.create(options)
84+
return Response.json({"status": "success"})
8285
```
8386

8487
:::note

src/content/docs/workflows/python/python-workers-api.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,13 @@ class DemoWorkflowClass(WorkflowEntrypoint):
141141

142142
### Create an instance via binding
143143

144-
Note that `env` is a Javascript object exposed to the Python script via [JsProxy](https://pyodide.org/en/stable/usage/api/python-api/ffi.html#pyodide.ffi.JsProxy). You can
145-
access the binding like you would on a Javascript worker. Refer to the [Workflow binding documentation](/workflows/build/workers-api/#workflow) to learn more about the methods available.
144+
Note that `env` is a JavaScript object exposed to the Python script via [JsProxy](https://pyodide.org/en/stable/usage/api/python-api/ffi.html#pyodide.ffi.JsProxy). You can access the binding like you would on a JavaScript worker. Refer to the [Workflow binding documentation](/workflows/build/workers-api/#workflow) to learn more about the methods available.
146145

147146
Let's consider the previous binding called `MY_WORKFLOW`. Here's how you would create a new instance:
148147

149148
```python
150-
async def on_fetch(request, env):
151-
instance = await env.MY_WORKFLOW.create()
152-
return Response.json({"status": "success"})
149+
class Default(WorkerEntrypoint):
150+
async def fetch(self, request):
151+
instance = await self.env.MY_WORKFLOW.create()
152+
return Response.json({"status": "success"})
153153
```

0 commit comments

Comments
 (0)