| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/workers/languages/python/how-python-workers-work/ | [Back] [Original] |
Workers written in Python are executed by Pyodide . Pyodide is a CPython (the reference implementation of Python commonly referred to as just "Python") compiled to WebAssembly.
When you write a Python Worker, your code is interpreted directly by Pyodide, within a V8 isolate. Refer to How Workers works to learn more.
A basic Python Worker includes a Python file with a Default class extending WorkerEntrypoint, such as:
from workers import Response, WorkerEntrypoint
class Default(WorkerEntrypoint):
async def fetch(self, request):
return Response("Hello world!")
...and a Wrangler configuration file that points to this .py file:
{
"$schema": "./node_modules/wrangler/config-schema.json",
"name": "hello-world-python-worker",
"main": "src/entry.py",
// Set this to today's date
"compatibility_date": "2026-08-19"
}"$schema" = "./node_modules/wrangler/config-schema.json"
name = "hello-world-python-worker"
main = "src/entry.py"
# Set this to today's date
compatibility_date = "2026-08-19"When you run uv run pywrangler dev to do local dev, the Workers runtime will:
pyproject.toml fileThere are no extra toolchain or precompilation steps needed. The Python execution environment is provided directly by the Workers runtime, mirroring how Workers written in JavaScript work.
Refer to the Python examples to learn how to use Python within Workers.
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 uv run pywrangler deploy, the following happens:
pyproject.toml to the Workers API.When a request comes in to your Worker, we load this snapshot and use it to bootstrap your Worker in an isolate, avoiding expensive initialization time:
[Diagram of how Python Workers are deployed to Cloudflare]
Refer to the blog post introducing Python Workers for more detail about performance optimizations and how the Workers runtime will reduce cold starts for Python Workers.
A new version of Python is released every year in August, and a new version of Pyodide is released six (6) months later. When this new version of Pyodide is published, we will add it to Workers by gating it behind a Compatibility Flag, which is only enabled after a specified Compatibility Date. This lets us continually provide updates, without risk of breaking changes, extending the commitment weve made for JavaScript to Python.
Each Python release has a five (5) year support window . Once this support window has passed for a given version of Python, security patches are no longer applied, making this version unsafe to rely on. Following the Workers Runtime policy to never break an application that is live in production, existing Python Workers on versions outside the support window will continue to work. However, we do not recommend using Python versions outside the support window for new projects, and we will not provide patches for issues arising from using these versions. We also cannot guarantee that these older Python versions won't suffer from degraded performance, including higher latency or CPU time usage.
| Web Proxy Viewer | New URL | Original Page |