Registry / aws / cloudflare-workers

cloudflare-workers

JSON →
library0.0.8pypypi✓ verified 50d ago

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.

aws
pip install cloudflare-workers
Install & Compatibility
Where this runs
tested against v0.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
3/5 runs
3/5 runs
py 3.11
3/5 runs
3/5 runs
py 3.12
3/5 runs
3/5 runs
py 3.13
3/5 runs
3/5 runs
py 3.9
3/5 runs
3/5 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

KeyValueStore
from cloudflare_workers import KeyValueStore
from cloudflare.workers import Response
key_value_store
from cloudflare_workers import key_value_store
from cloudflare.workers import Response

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 async def on_fetch(request, env): return Response('Hello from Python Workers!')
Debug
Known issues
breakingThe import path is 'cloudflare.workers', NOT 'cloudflare_workers'. The pip package name uses a hyphen but the import namespace uses a dot.
fix
from cloudflare.workers import Response
affects: all
gotchaThis package conflicts with the 'cloudflare' PyPI package (the Cloudflare API client). Both occupy the 'cloudflare' namespace. Do not install both in the same environment.
fix
Use separate virtual environments if you need both the Workers SDK and the Cloudflare API client.
affects: all
gotchaPython Workers run on Pyodide (CPython in WebAssembly). Not all Python packages are available. Only pure-Python packages and select packages with Pyodide builds are supported.
fix
Check the Pyodide package list for availability. C-extension packages generally won't work unless explicitly ported.
affects: all
gotchaThe handler function must be async. Synchronous handlers will fail silently or raise errors at runtime.
fix
Always define your handler as 'async def on_fetch(request, env):' not 'def on_fetch(request, env):'.
affects: all
gotchaPython Workers require compatibility_flags = ["python_workers"] in wrangler.toml and main must point to a .py file. Without this flag, deployment fails.
fix
Add compatibility_flags = ["python_workers"] and set main = "src/entry.py" in wrangler.toml.
affects: all
deprecatedPython Workers support is still in open beta. APIs may change between releases without following semver strictly.
fix
Pin your cloudflare-workers version and test thoroughly before upgrading.
affects: all
breakingThe 'cloudflare-workers' package must be installed in your environment for imports like 'from cloudflare.workers import Response' to succeed. Missing the package will result in a ModuleNotFoundError for 'cloudflare'.
fix
Add 'cloudflare-workers' to your requirements.txt or install via pip: `pip install cloudflare-workers`
affects: all
Upgrade
Version history
0.0.1latest on PyPI
Audit
Dependencies
wranglerrequiredRequired for local development, testing, and deploying Workers. Installed via npm, not pip.
Agent activity
92 hits · last 30 days
node
14
mj12bot
3
seranking-bot
3
ahrefsbot
2
Amazon
1
amazonbot
1
googlebot
1
Resources