You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/languages/python/basics.mdx
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,15 +149,21 @@ and compatibility_flags in your config file.
149
149
150
150
## Upgrading `pywrangler`
151
151
152
-
To upgrade to the latest version of `pywrangler`, run the following command:
152
+
To upgrade to the latest version of `pywrangler` globally, run the following command:
153
153
154
154
```bash
155
155
uv tool upgrade workers-py
156
156
```
157
157
158
+
To upgrade to the latest version of `pywrangler` in a specific project, run the following command:
159
+
160
+
```bash
161
+
uv lock --upgrade-package workers-py
162
+
```
163
+
158
164
## Next Up
159
165
160
-
- Learn details about local development, deployment, and [how to Python Workers work](/workers/languages/python/how-python-workers-work).
166
+
- Learn details about local development, deployment, and [how Python Workers work](/workers/languages/python/how-python-workers-work).
161
167
- Explore the [package](/workers/languages/python/packages) docs for instructions on how to use packages with Python Workers.
162
168
- Understand which parts of the [Python Standard Library](/workers/languages/python/stdlib) are supported in Python Workers.
163
169
- Learn about Python Workers' [foreign function interface (FFI)](/workers/languages/python/ffi), and how to use it to work with [bindings](/workers/runtime-apis/bindings) and [Runtime APIs](/workers/runtime-apis/).
Copy file name to clipboardExpand all lines: src/content/docs/workers/languages/python/ffi.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ Under the hood, `env` is actually a JavaScript object. When you call `.FOO`, you
52
52
53
53
### Converting Python to JavaScript
54
54
55
-
Occasionally, to interoperate with JavaScript APIs, you may need to convert a Python objebect to JavaScript. Pyodide provides a `to_js` function to facilitate this conversion.
55
+
Occasionally, to interoperate with JavaScript APIs, you may need to convert a Python object to JavaScript. Pyodide provides a `to_js` function to facilitate this conversion.
56
56
57
57
````python
58
58
from js import Object
@@ -66,6 +66,8 @@ def to_js(obj):
66
66
```
67
67
````
68
68
69
+
For more details, see out the [documentation on `pyodide.ffi.to_js`](https://pyodide.org/en/stable/usage/api/python-api/ffi.html#pyodide.ffi.to_js).
70
+
69
71
## Using JavaScript globals from Python Workers
70
72
71
73
When writing Workers in Python, you can access JavaScript globals by importing them from the `js` module. For example, note how `Response` is imported from `js` in the example below:
Copy file name to clipboardExpand all lines: src/content/docs/workers/languages/python/index.mdx
+8-11Lines changed: 8 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,6 @@ import { WranglerConfig } from "~/components";
15
15
16
16
Cloudflare Workers provides a first-class Python experience, including support for:
17
17
18
-
- The majority of Python's [Standard library](/workers/languages/python/stdlib/)
19
18
- Easy to install and fast-booting [Packages](/workers/languages/python/packages), including [FastAPI](https://fastapi.tiangolo.com/), [Langchain](https://pypi.org/project/langchain/), [httpx](https://www.python-httpx.org/), [Pydantic](https://docs.pydantic.dev/latest/) and more.
20
19
- A robust [foreign function interface (FFI)](/workers/languages/python/ffi) that lets you use JavaScript objects and functions directly from Python — including all [Runtime APIs](/workers/runtime-apis/)
21
20
- An ecosystem of services on the Workers Platform accessible via [bindings](/workers/runtime-apis/bindings/), including:
@@ -25,15 +24,6 @@ Cloudflare Workers provides a first-class Python experience, including support f
25
24
- File storage with [R2](/r2)
26
25
-[Durable Workflows](/workflows/), [Queues](/queues/), and [ more](/workers/runtime-apis/bindings/)
27
26
28
-
:::caution[Python Workers are in beta.]
29
-
30
-
You must add the `python_workers` compatibility flag to your Worker, while Python Workers are in open beta. Packages are supported using the [pywrangler](/workers/languages/python/packages) tool.
31
-
32
-
We also recommend using the `python_dedicated_snapshot` for improved performance when using packages.
33
-
34
-
We'd love your feedback. 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.
35
-
:::
36
-
37
27
## Introduction
38
28
39
29
A Python Worker can be as simple as four lines of code:
@@ -51,6 +41,13 @@ sent to the Worker.
51
41
52
42
In a Python Worker, this handler is placed in a `Default` class that extends the `WorkerEntrypoint` class (which you can import from the `workers` SDK module).
53
43
44
+
:::caution[Python Workers are in beta.]
45
+
46
+
You must add the `python_workers` compatibility flag to your Worker, while Python Workers are in open beta. Packages are supported using the [pywrangler](/workers/languages/python/packages) tool.
47
+
48
+
We'd love your feedback. 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.
49
+
:::
50
+
54
51
### The `pywrangler` CLI tool
55
52
56
53
To run a Python Worker locally, install packages, and deploy it to Cloudflare, you use [pywrangler](https://github.com/cloudflare/workers-py),
@@ -80,7 +77,7 @@ To deploy a Python Worker to Cloudflare, run `pywrangler deploy`:
80
77
uv run pywrangler deploy
81
78
```
82
79
83
-
### Python Worker Templaes
80
+
### Python Worker Templates
84
81
85
82
When you initialize a new Python Worker project and select from one of many templates:
Copy file name to clipboardExpand all lines: src/content/docs/workers/runtime-apis/handlers/scheduled.mdx
+7-3Lines changed: 7 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,7 +61,7 @@ from workers import WorkerEntrypoint, Response, fetch
61
61
62
62
classDefault(WorkerEntrypoint):
63
63
asyncdefscheduled(self, controller, env, ctx):
64
-
ctx.waitUntil(doSomeTaskOnASchedule())
64
+
ctx.waitUntil(doSomeTaskOnASchedule())
65
65
```
66
66
67
67
</TabItem></Tabs>
@@ -87,5 +87,9 @@ class Default(WorkerEntrypoint):
87
87
88
88
When a Workers script is invoked by a [Cron Trigger](/workers/configuration/cron-triggers/), the Workers runtime starts a `ScheduledEvent` which will be handled by the `scheduled` function in your Workers Module class. The `ctx` argument represents the context your function runs in, and contains the following methods to control what happens next:
- Use this method to notify the runtime to wait for asynchronous tasks (for example, logging, analytics to third-party services, streaming and caching). The first `ctx.waitUntil` to fail will be observed and recorded as the status in the [Cron Trigger](/workers/configuration/cron-triggers/) Past Events table. Otherwise, it will be reported as a success.
90
+
- <code>ctx.waitUntil(promisePromise)</code> : void - Use this method to notify
91
+
the runtime to wait for asynchronous tasks (for example, logging, analytics to
92
+
third-party services, streaming and caching). The first `ctx.waitUntil` to
93
+
fail will be observed and recorded as the status in the [Cron
94
+
Trigger](/workers/configuration/cron-triggers/) Past Events table. Otherwise,
Copy file name to clipboardExpand all lines: src/content/docs/workflows/python/bindings.mdx
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -93,9 +93,8 @@ The `create` method returns a [`WorkflowInstance`](/workflows/build/workers-api/
93
93
94
94
Create (trigger) a batch of new workflow instances, up to 100 instances at a time. This is useful if you need to create multiple instances at once within the [instance creation limit](/workflows/reference/limits/).
95
95
96
-
- <code>create_batch(batch)</code>*`batch` - list of
97
-
`WorkflowInstanceCreateOptions` to pass when creating an instance, including a
98
-
user-provided ID and payload parameters.
96
+
* <code>create_batch(batch)</code>
97
+
*`batch` - list of `WorkflowInstanceCreateOptions` to pass when creating an instance, including a user-provided ID and payload parameters.
99
98
100
99
Each element of the `batch` list is expected to include both `id` and `params` properties:
0 commit comments