| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/workers/languages/python/ | [Back] [Original] |
Cloudflare Workers provides a first-class Python experience, including support for:
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).
Python Workers are in beta.
You must add the python_workers compatibility flag to your Worker, while Python Workers are in open beta.
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.
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
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/01-hello
| Web Proxy Viewer | New URL | Original Page |