Skip to content

Commit d233d45

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

File tree

1 file changed

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

1 file changed

+18
-8
lines changed

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

Lines changed: 18 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,25 @@ 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 tool install workers-py
58+
uv run pywrangler init
59+
```
60+
This will create a `pyproject.toml` file with `workers-py` as a development
61+
dependency. `pywrangler init` will create a wrangler config file. You can then
62+
run `pywrangler` with:
5263

5364
```bash
54-
npx wrangler@latest dev
65+
uv run pywrangler dev
5566
```
5667

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

5970
```bash
60-
npx wrangler@latest deploy
71+
uv run pywrangler deploy
6172
```
6273

6374
## Modules
@@ -116,10 +127,9 @@ curl --header "Content-Type: application/json" \
116127
Hello, Python!
117128
```
118129

119-
## The `env` Parameter
130+
## The `env` Attribute
120131

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
132+
The `env` attribute on the ``WorkerEntrypoint`` can be used to access
123133
[environment variables](/workers/configuration/environment-variables/),
124134
[secrets](/workers/configuration/secrets/),and
125135
[bindings](/workers/runtime-apis/bindings/).

0 commit comments

Comments
 (0)