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 hellouvx --from workers-py pywrangler devb key to open a browser tab, and make a request to your WorkerYou can run uvx --from workers-py pywrangler dev in any example project directory to run a local development server using Pywrangler, the CLI for Cloudflare Python 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.
hello/ — the most basic Python Workerbinding/ — shows how bindings work in Python Workers. Put a key into Workers KV, and then read it.fastapi/ — demonstrates how to use the FastAPI package with Python Workersquery-d1/ - shows how to query D1 with Python Workerslangchain/ — demonstrates how to use the LangChain package with Python Workers. Currently broken.assets/ — An example with an assets binding.durable-objects/ — An example with storing state in a Durable Object.cron/ — shows a simple cron job.workers-ai/ makes a call Workers AI to run inference on Cloudflare's Global Network.workflows/ — shows a durable Workflows example.opengraph/ — shows how to use HTMLRewriter to generate OpenGraph images with Python Workers.image-gen/ — shows how to use Pillow to generate images with Python Workers.js-api-pygments/ — shows how to use Pygments to highlight code with Python Workers.websocket-stream-consumer/ — shows how to use WebSocket to consume a stream of data with Python Workers.chatroom/ - A real-time chatroom using WebSocket.sync-http-clients/ — demonstrates outbound HTTP with synchronous Python clients (requests, urllib3, and httpx.Client).dynamic-py-py/ — shows how to load and run a Python Worker dynamically at runtime using a Worker Loader binding.django/ — runs a naive Django WSGI application directly on Python Workers.django-todo-d1/ — uses Django with D1 for a basic TODO application.image-redraw/ — an example that combines FastAPI, R2, Queues, Workflows and Workers AI to redraw uploaded images.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.
The Apache 2.0 license.
Python
58.6%
HTML
20.1%
JavaScript
10.5%
CSS
9.7%
TypeScript
1.2%
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 hellouvx --from workers-py pywrangler devb key to open a browser tab, and make a request to your WorkerYou can run uvx --from workers-py pywrangler dev in any example project directory to run a local development server using Pywrangler, the CLI for Cloudflare Python 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.
hello/ — the most basic Python Workerbinding/ — shows how bindings work in Python Workers. Put a key into Workers KV, and then read it.fastapi/ — demonstrates how to use the FastAPI package with Python Workersquery-d1/ - shows how to query D1 with Python Workerslangchain/ — demonstrates how to use the LangChain package with Python Workers. Currently broken.assets/ — An example with an assets binding.durable-objects/ — An example with storing state in a Durable Object.cron/ — shows a simple cron job.workers-ai/ makes a call Workers AI to run inference on Cloudflare's Global Network.workflows/ — shows a durable Workflows example.opengraph/ — shows how to use HTMLRewriter to generate OpenGraph images with Python Workers.image-gen/ — shows how to use Pillow to generate images with Python Workers.js-api-pygments/ — shows how to use Pygments to highlight code with Python Workers.websocket-stream-consumer/ — shows how to use WebSocket to consume a stream of data with Python Workers.chatroom/ - A real-time chatroom using WebSocket.sync-http-clients/ — demonstrates outbound HTTP with synchronous Python clients (requests, urllib3, and httpx.Client).dynamic-py-py/ — shows how to load and run a Python Worker dynamically at runtime using a Worker Loader binding.django/ — runs a naive Django WSGI application directly on Python Workers.django-todo-d1/ — uses Django with D1 for a basic TODO application.image-redraw/ — an example that combines FastAPI, R2, Queues, Workflows and Workers AI to redraw uploaded images.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.
The Apache 2.0 license.
Python
58.6%
HTML
20.1%
JavaScript
10.5%
CSS
9.7%
TypeScript
1.2%