Skip to content

Commit 9f68aaf

Browse files
committed
Rename to cf-requirements and add pywrangler section.
1 parent c99a23e commit 9f68aaf

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
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 your `cf-requirements.txt` file to the Workers API.
54+
2. Cloudflare sends your Python code, and your `cf-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 `cf-requirements.txt` file.
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: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,60 @@ head:
88

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

11-
<Render file="python-workers-beta-packages" product="workers" />
11+
## Using pywrangler
1212

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/).
13+
[Pywrangler](https://github.com/cloudflare/workers-py?tab=readme-ov-file#pywrangler) is a CLI tool for managing packages in a Python Workers
14+
project. By default, it will vendor any packages you have defined in your pyproject.toml file.
15+
16+
To get started, create a pyproject.toml file with the following contents:
17+
18+
```
19+
[project]
20+
name = "YourProjectName"
21+
version = "0.1.0"
22+
description = "Add your description here"
23+
requires-python = ">=3.12"
24+
dependencies = [
25+
"fastapi"
26+
]
27+
28+
[dependency-groups]
29+
dev = ["workers-py"]
30+
```
31+
32+
The above will allow your worker to depend on the [FastAPI](https://fastapi.tiangolo.com/) package.
33+
34+
You can then run `uv run pywrangler sync` to install the packages in your project, in such a way so that they will be deployed along with your
35+
Worker.
36+
37+
The `pywrangler` CLI also supports all commands supported by the `wrangler` tool, so you can use it to deploy your Worker, add environment variables, etc.
38+
39+
For example, to run your Worker locally, you can run `uv run pywrangler dev`. This will automatically run `sync` for you, so you don't need to do so manually.
40+
41+
## Built-in packages
42+
43+
:::caution[Explicitly defined built-in packages are deprecated]
44+
45+
You can still specify packages in a `cf-requirements.txt` file, but doing so is deprecated. Instead use `pywrangler` to add packages to your Worker as described above.
46+
:::
47+
48+
To import a Python package, add the package name to the `cf-requirements.txt` file within the same directory as your [Wrangler configuration file](/workers/wrangler/configuration/).
1449

1550
For example, if your Worker depends on [FastAPI](https://fastapi.tiangolo.com/), you would add the following:
1651

1752
```
1853
fastapi
1954
```
2055

21-
## Package versioning
56+
### Package versioning
2257

23-
In the example above, you likely noticed that there is no explicit version of the Python package declared in `requirements.txt`.
58+
In the example above, you likely noticed that there is no explicit version of the Python package declared in `cf-requirements.txt`.
2459

2560
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.
2661

2762
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.
2863

29-
## Supported Packages
64+
### Supported Packages
3065

3166
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:
3267

@@ -80,6 +115,6 @@ A subset of the [Python packages that Pyodide supports](https://pyodide.org/en/l
80115

81116
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).
82117

83-
## HTTP Client Libraries
118+
### HTTP Client Libraries
84119

85120
Only HTTP libraries that are able to make requests asynchronously are supported. Currently, these include [`aiohttp`](https://docs.aiohttp.org/en/stable/index.html) and [`httpx`](https://www.python-httpx.org/). You can also use the [`fetch()` API](/workers/runtime-apis/fetch/) from JavaScript, using Python Workers' [foreign function interface](/workers/languages/python/ffi) to make HTTP requests.

0 commit comments

Comments
 (0)