Skip to content

Commit 964c17d

Browse files
authored
Rename to cf-requirements and add pywrangler section. (#23517)
1 parent 943cde7 commit 964c17d

File tree

2 files changed

+31
-65
lines changed

2 files changed

+31
-65
lines changed

src/content/docs/workers/languages/python/how-python-workers-work.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ Refer to the [Python examples](/workers/languages/python/examples/) to learn how
5050

5151
To reduce cold start times, when you deploy a Python Worker, Cloudflare performs as much of the expensive work as possible upfront, at deploy time. When you run npx `wrangler@latest deploy`, the following happens:
5252

53-
1. Wrangler uploads your Python code and your `requirements.txt` file to the Workers API.
54-
2. Cloudflare sends your Python code, and your `requirements.txt` file to the Workers runtime to be validated.
55-
3. Cloudflare creates a new v8 isolate for your Worker, and automatically injects Pyodide plus any packages you’ve specified in your `requirements.txt` file.
53+
1. Wrangler uploads your Python code and any vendored packages to the Workers API.
54+
2. Cloudflare sends your Python code, and any vendored packages to the Workers runtime to be validated.
55+
3. Cloudflare creates a new v8 isolate for your Worker, and automatically injects Pyodide plus any built-in packages requested by your bundle.
5656
4. Cloudflare scans the Worker’s code for import statements, execute them, and then take a snapshot of the Worker’s WebAssembly linear memory. Effectively, we perform the expensive work of importing packages at deploy time, rather than at runtime.
5757
5. Cloudflare deploys this snapshot alongside your Worker’s Python code to the Cloudflare network.
5858

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

Lines changed: 28 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -8,77 +8,43 @@ head:
88

99
import { Render } from "~/components";
1010

11-
<Render file="python-workers-beta-packages" product="workers" />
11+
[Pywrangler](https://github.com/cloudflare/workers-py?tab=readme-ov-file#pywrangler) is a CLI tool for managing packages and Python Workers.
12+
It is meant as a wrapper for wrangler that sets up a full environment for you, including bundling your packages into
13+
your worker bundle on deployment.
14+
15+
To get started, create a pyproject.toml file with the following contents:
16+
17+
```toml
18+
[project]
19+
name = "YourProjectName"
20+
version = "0.1.0"
21+
description = "Add your description here"
22+
requires-python = ">=3.12"
23+
dependencies = [
24+
"fastapi"
25+
]
26+
27+
[dependency-groups]
28+
dev = ["workers-py"]
29+
```
1230

13-
To import a Python package, add the package name to the `requirements.txt` file within the same directory as your [Wrangler configuration file](/workers/wrangler/configuration/).
31+
The above will allow your worker to depend on the [FastAPI](https://fastapi.tiangolo.com/) package.
1432

15-
For example, if your Worker depends on [FastAPI](https://fastapi.tiangolo.com/), you would add the following:
33+
To run the worker locally:
1634

1735
```
18-
fastapi
36+
uv run pywrangler dev
1937
```
2038

21-
## Package versioning
22-
23-
In the example above, you likely noticed that there is no explicit version of the Python package declared in `requirements.txt`.
24-
25-
In Workers, Python package versions are set via [Compatibility Dates](/workers/configuration/compatibility-dates/) and [Compatibility Flags](/workers/configuration/compatibility-flags/). Given a particular compatibility date, a specific version of the [Pyodide Python runtime](https://pyodide.org/en/stable/project/changelog.html) is provided to your Worker, providing a specific set of Python packages pinned to specific versions.
26-
27-
As new versions of Pyodide and additional Python packages become available in Workers, we will publish compatibility flags and their associated compatibility dates here on this page.
39+
To deploy your worker:
2840

29-
## Supported Packages
30-
31-
A subset of the [Python packages that Pyodide supports](https://pyodide.org/en/latest/usage/packages-in-pyodide.html) are provided directly by the Workers runtime:
41+
```
42+
uv run pywrangler deploy
43+
```
3244

33-
- aiohttp: 3.9.3
34-
- aiohttp-tests: 3.9.3
35-
- aiosignal: 1.3.1
36-
- annotated-types: 0.6.0
37-
- annotated-types-tests: 0.6.0
38-
- anyio: 4.2.0
39-
- async-timeout: 4.0.3
40-
- attrs: 23.2.0
41-
- certifi: 2024.2.2
42-
- charset-normalizer: 3.3.2
43-
- distro: 1.9.0
44-
- [fastapi](/workers/languages/python/packages/fastapi): 0.110.0
45-
- frozenlist: 1.4.1
46-
- h11: 0.14.0
47-
- h11-tests: 0.14.0
48-
- hashlib: 1.0.0
49-
- httpcore: 1.0.4
50-
- httpx: 0.27.0
51-
- idna: 3.6
52-
- jsonpatch: 1.33
53-
- jsonpointer: 2.4
54-
- langchain: 0.1.8
55-
- langchain-core: 0.1.25
56-
- langchain-openai: 0.0.6
57-
- langsmith: 0.1.5
58-
- lzma: 1.0.0
59-
- micropip: 0.6.0
60-
- multidict: 6.0.5
61-
- numpy: 1.26.4
62-
- numpy-tests: 1.26.4
63-
- openai: 1.12.0
64-
- openssl: 1.1.1n
65-
- packaging: 23.2
66-
- pydantic: 2.6.1
67-
- pydantic-core: 2.16.2
68-
- pydecimal: 1.0.0
69-
- pydoc-data: 1.0.0
70-
- pyyaml: 6.0.1
71-
- regex: 2023.12.25
72-
- regex-tests: 2023.12.25
73-
- requests: 2.31.0
74-
- six: 1.16.0
75-
- sniffio: 1.3.0
76-
- sniffio-tests: 1.3.0
77-
- sqlite3: 1.0.0
78-
- ssl: 1.0.0
79-
- starlette: 0.36.3
45+
Your dependencies will get bundled with your worker automatically on deployment.
8046

81-
Looking for a package not listed here? Tell us what you'd like us to support by [opening a discussion on Github](https://github.com/cloudflare/workerd/discussions/new?category=python-packages).
47+
The `pywrangler` CLI also supports all commands supported by the `wrangler` tool, for the full list of commands run `uv run pywrangler --help`.
8248

8349
## HTTP Client Libraries
8450

0 commit comments

Comments
 (0)