Cloudflare Workers provides a first-class Python experience, including support for:
- Easy to install and fast-bootingPackages, includingFastAPI ↗,Langchain ↗,httpx ↗,Pydantic ↗ and more.
- A robustforeign function interface (FFI) that lets you use JavaScript objects and functions directly from Python — including allRuntime APIs
- An ecosystem of services on the Workers Platform accessible viabindings, including:
- State storage and databases likeKV,D1,Durable Objects
- Access toEnvironment Variables,Secrets, and other Workers usingService Bindings
- AI capabilities withWorkers AI,Vectorize
- File storage withR2
- Durable Workflows,Queues, and more
A Python Worker can be as simple as four lines of code:
from workersimport WorkerEntrypoint, ResponseclassDefault(WorkerEntrypoint):asyncdeffetch(self,request):returnResponse("Hello World!")Similar to other Workers, the main entry point for a Python worker is thefetch handler which handles incoming requestssent to the Worker.
In a Python Worker, this handler is placed in aDefault class that extends theWorkerEntrypoint class (which you can import from theworkers SDK module).
You must add thepython_workers compatibility flag to your Worker, while Python Workers are in open beta. Packages are supported using thepywrangler tool.
We'd love your feedback. Join the #python-workers channel in theCloudflare Developers Discord ↗ and let us know what you'd like to see next.
To run a Python Worker locally, install packages, and deploy it to Cloudflare, you usepywrangler ↗,the CLI for Python Workers.
To set it up, first, ensureuv ↗ andNode ↗ are installed.
Then set up your development environment:
uv inituv tool install workers-pyuv run pywrangler initThis will create apyproject.toml file withworkers-py as a developmentdependency.pywrangler init will create a wrangler config file. You can thenrunpywrangler with:
uvrunpywranglerdevTo deploy a Python Worker to Cloudflare, runpywrangler deploy:
uvrunpywranglerdeployWhen you initialize a new Python Worker project and select from one of many templates:
uvrunpywranglerinitOr you can clone the examples repository to explore more options:
gitclonehttps://github.com/cloudflare/python-workers-examplescdpython-workers-examples/01-hello- Learn more aboutthe basics of Python Workers
- Learn details about local development, deployment, andhow to Python Workers work.
- Explore thepackage docs for instructions on how to use packages with Python Workers.
- Understand which parts of thePython Standard Library are supported in Python Workers.
- Learn about Python Workers'foreign function interface (FFI), and how to use it to work withbindings andRuntime APIs.