Python SDK for building Cloudflare Workers. Allows writing serverless functions in Python that run on the Cloudflare edge network using Pyodide (CPython compiled to WebAssembly). This is distinct from the 'cloudflare' package which is the API client for managing Cloudflare resources.
pip install cloudflare-workersVerified import paths — ran on the pinned version, not inferred.
Minimal Cloudflare Worker in Python. The on_fetch handler is the entry point for HTTP requests. Deploy with wrangler after configuring wrangler.toml with compatibility_flags = ["python_workers"].
from cloudflare.workers import Response
Use separate virtual environments if you need both the Workers SDK and the Cloudflare API client.
Check the Pyodide package list for availability. C-extension packages generally won't work unless explicitly ported.
Always define your handler as 'async def on_fetch(request, env):' not 'def on_fetch(request, env):'.
Add compatibility_flags = ["python_workers"] and set main = "src/entry.py" in wrangler.toml.
Pin your cloudflare-workers version and test thoroughly before upgrading.
Add 'cloudflare-workers' to your requirements.txt or install via pip: `pip install cloudflare-workers`