This is a collection of examples for writing Cloudflare Workers in Python. Use these examples to learn how Python Workers work.
git clone https://github.com/cloudflare/python-workers-examplescd 01-hellonpx wrangler@latest dev- Press the
bkey to open a browser tab, and make a request to your Worker
You can run npx wrangler@latest dev in any example project directory to run a local development server using Wrangler, the CLI for Cloudflare Workers. This local development server is powered by workerd, the open-source Workers runtime.
Need to deploy your Worker to Cloudflare? Python Workers are in open beta and have a few limitations.
01-hello/— the most basic Python Worker02-binding/— shows how bindings work in Python Workers. Put a key into Workers KV, and then read it.03-fastapi/— demonstrates how to use the FastAPI package with Python Workers04-query-d1/- shows how to query D1 with Python Workers05-langchain/— demonstrates how to use the LangChain package with Python Workers. Currently broken.06-assets/— An example with an assets binding.07-durable-objects/— An example with storing state in a Durable Object.08-cron/— shows a simple cron job.09-workers-ai/makes a call Workers AI to run inference on Cloudflare's Global Network.10-workflows/— shows a durable Workflows example.
- Python Workers are in open beta. You can use packages in your Workers by using the pywrangler tool.
- You must add the
python_workerscompatibility 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.
The Apache 2.0 license.