Python Workers (2)
Last updated Sep 17, 2026 Cloudflare Workers provides a first-class Python experience, including support for:
- Easy to install and fast-booting Packages, including FastAPI ↗︎, Langchain ↗︎, Pydantic ↗︎ and more.
- A robust foreign function interface (FFI) that lets you use JavaScript objects and functions directly from Python — including all Runtime APIs
- An ecosystem of services on the Workers Platform accessible via bindings, including:
- State storage and databases like KV, D1, Durable Objects
- Access to Environment Variables, Secrets, and other Workers using Service Bindings
- AI capabilities with Workers AI, Vectorize
- File storage with R2
- Durable Workflows, Queues, and more
Introduction
A Python Worker can be as simple as four lines of code:
from workers import WorkerEntrypoint, Response
class Default(WorkerEntrypoint):
async def fetch(self, request):
return Response("Hello World!")
Similar to other Workers, the main entry point for a Python worker is the fetch handler which handles incoming requests sent to the Worker.
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).
Note
You must add the python_workers compatibility flag to your Worker.
We'd love your feedback. Join the #python-workers channel in the Cloudflare Developers Discord ↗︎ and let us know what you'd like to see next.
The pywrangler CLI tool
To run a Python Worker locally, install packages, and deploy it to Cloudflare, you use pywrangler ↗︎, the CLI for Python Workers.
To set it up, first, ensure uv ↗︎ and Node ↗︎ are installed.
Then set up your development environment:
uvx --from workers-py pywrangler init
This will create a pyproject.toml file with workers-py as a development dependency. pywrangler init will create a wrangler config file. You can then run pywrangler with:
uv run pywrangler dev
To deploy a Python Worker to Cloudflare, run pywrangler deploy:
uv run pywrangler deploy
Python Worker Templates
When you initialize a new Python Worker project and select from one of many templates:
uv run pywrangler init
Or you can clone the examples repository to explore more options:
git clone https://github.com/cloudflare/python-workers-examples
cd python-workers-examples/hello
Next Up
- Learn more about the basics of Python Workers
- Learn details about local development, deployment, and how to Python Workers work.
- Explore the package docs for instructions on how to use packages with Python Workers.
- Understand which parts of the Python Standard Library are supported in Python Workers.
- Learn about Python Workers' foreign function interface (FFI), and how to use it to work with bindings and Runtime APIs.
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"WebPage","@id":"https://developers.cloudflare.com/workers/languages/python/#page","headline":"Python Workers","description":"Write Workers in 100% Python","url":"https://developers.cloudflare.com/workers/languages/python/","inLanguage":"en","image":"https://developers.cloudflare.com/workers/languages/python/og.png?v=900a36ef7801c922","dateModified":"2026-09-17","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}
description: Learn the basics of Python Workers title: The Basics image: https://developers.cloudflare.com/workers/languages/python/basics/og.png?v=34d0ab0db9ff32c9
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers/llms.txt
Use this file to discover all available pages before exploring further.
Docs