Skip to content

Commit a7ca15b

Browse files
committed
Use pywrangler in the python overview
1 parent cd01d50 commit a7ca15b

File tree

1 file changed

+16
-8
lines changed
  • src/content/docs/workers/languages/python

1 file changed

+16
-8
lines changed

src/content/docs/workers/languages/python/index.mdx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ We'd love your feedback. Join the #python-workers channel in the [Cloudflare Dev
3030

3131
## Get started
3232

33+
You need [uv](https://docs.astral.sh/uv/#installation) and Node.
34+
3335
```bash
3436
git clone https://github.com/cloudflare/python-workers-examples
3537
cd python-workers-examples/01-hello
36-
npx wrangler@latest dev
38+
uv run pywrangler dev
3739
```
3840

3941
A Python Worker can be as simple as three lines of code:
@@ -48,16 +50,23 @@ class Default(WorkerEntrypoint):
4850

4951
Similar to Workers written in [JavaScript](/workers/languages/javascript), [TypeScript](/workers/languages/typescript), or [Rust](/workers/languages/rust/), the main entry point for a Python worker is the [`fetch` handler](/workers/runtime-apis/handlers/fetch). 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).
5052

51-
To run a Python Worker locally, you use [Wrangler](/workers/wrangler/), the CLI for Cloudflare Workers:
53+
To run a Python Worker locally, you use pywrangler, the CLI for Python Workers.
54+
To set it up, first you need to set up your development environment:
55+
```
56+
uv init
57+
uv add --dev workers-py
58+
```
59+
This will create a `pyproject.toml` file with `workers-py` as a development
60+
dependency. You can then run `pywrangler` with:
5261

5362
```bash
54-
npx wrangler@latest dev
63+
uv run pywrangler dev
5564
```
5665

57-
To deploy a Python Worker to Cloudflare, run [`wrangler deploy`](/workers/wrangler/commands/#deploy):
66+
To deploy a Python Worker to Cloudflare, run `pywrangler deploy`:
5867

5968
```bash
60-
npx wrangler@latest deploy
69+
uv run pywrangler deploy
6170
```
6271

6372
## Modules
@@ -116,10 +125,9 @@ curl --header "Content-Type: application/json" \
116125
Hello, Python!
117126
```
118127

119-
## The `env` Parameter
128+
## The `env` Attribute
120129

121-
In addition to the `request` parameter, the `env` parameter is also passed to
122-
the Python `fetch` handler and can be used to access
130+
The `env` attribute on the ``WorkerEntrypoint`` can be used to access
123131
[environment variables](/workers/configuration/environment-variables/),
124132
[secrets](/workers/configuration/secrets/),and
125133
[bindings](/workers/runtime-apis/bindings/).

0 commit comments

Comments
 (0)