You can now deploy FastAPI on Cloudflare Workers serverless without a JavaScript layer: Python Workers is GA as of September 21, 2026. Django and Flask also run, and databases connect to PostgreSQL or MySQL through Hyperdrive. Here’s how to set up an API with FastAPI and PostgreSQL on Workers, and what still doesn’t work.
What is Cloudflare Workers and what changes with Python GA?
Cloudflare Workers is Cloudflare’s serverless platform: your code runs on their global network, and the platform itself handles scaling and load balancing. Until now, Workers was essentially a JavaScript/TypeScript runtime, with Python available as an open beta since 2024.
GA means Cloudflare now treats Python as a first-class language, with full support on their development platform. In practice, three things changed:
- Bindings speak Python natively. Before you needed bridging code with
pyodide.ffi.to_jsto send a Python dictionary to a Queue. Nowself.env.QUEUE.send({"key": "value"})simply works. The same applies to Workers AI, R2, D1, Durable Objects, Queues, and Workflows. - Web frameworks run as-is. FastAPI (ASGI), and Django and Flask (WSGI), run through lightweight adapters that Cloudflare includes in their
workersSDK. Workers plays the role thatuvicornorgunicornwould play on a traditional server. - Databases and HTTP clients work. Cloudflare implemented socket system calls over the Workers
connectAPI, so standard drivers likeasyncpgcan open TCP connections, and libraries likeopenai,langchain, andmcpnow run natively.
Under the hood, Python Workers runs on Pyodide, a CPython-to-WebAssembly compilation. That defines which packages you can use (more below).
How do you deploy FastAPI on Cloudflare Workers?
You need two things installed: uv and Node.js. Everything else happens through pywrangler, the Python Workers CLI, which wraps Cloudflare’s wrangler and packages your Python dependencies on deploy.
1. Create the project
uvx --from workers-py pywrangler init
This creates a pyproject.toml with workers-py as a dev dependency, plus a Wrangler configuration file. If you prefer to write the files by hand, this is what Cloudflare’s FastAPI guide uses.
2. Declare your dependencies
pyproject.toml:
[project]
name = "my-fastapi-app"
version = "0.1.0"
requires-python = ">=3.13"
dependencies = [
"fastapi",
]
[dependency-groups]
dev = [
"workers-py",
"workers-runtime-sdk"
]
3. Write the application
src/main.py:
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
from workers import asgi
Default = asgi.entrypoint(app)
The last line is the only Workers-specific part. asgi.entrypoint(app) connects your FastAPI application to the Workers runtime, just as uvicorn main:app would on a VM.
4. Prepare the wrangler.jsonc file
wrangler.jsonc:
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-fastapi-app",
"main": "src/main.py",
// Set this to today's date
"compatibility_date": "2026-09-22",
"compatibility_flags": ["python_workers"]
}
The python_workers flag is still required, even though it’s now GA. The compatibility date also determines your Python version: starting from 2026-09-08, Workers uses Python 3.14 by default.
5. Test it locally and deploy
uv run pywrangler dev
curl http://localhost:8787/
# {"Hello":"World"}
uv run pywrangler deploy
pywrangler accepts all wrangler commands, so uv run pywrangler --help shows the full list.
How do you connect FastAPI to PostgreSQL on Cloudflare Workers?
You connect through Hyperdrive, Cloudflare’s connection pool for existing databases. It maintains an active pool within Cloudflare’s network and caches the most frequent read queries, so your Worker saves the round trips of TCP, TLS, and authentication on each request. Your database must be publicly accessible; for a private network, Cloudflare documents a separate setup with Workers VPC.
1. Create the Hyperdrive configuration
npx wrangler hyperdrive create <YOUR_CONFIG_NAME> --connection-string="postgres://user:password@HOSTNAME_OR_IP_ADDRESS:PORT/database_name"
The command returns an id. Copy it.
Note that Hyperdrive caches read results by default and doesn’t invalidate that cache when your application writes. If you need to read what you just wrote, the documentation recommends a second Hyperdrive configuration with caching disabled (--caching-disabled) for those reads.
2. Add the binding
Hyperdrive on Python Workers requires a compatibility date of 2026-09-08 or later.
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "my-fastapi-app",
"main": "src/main.py",
"compatibility_date": "2026-09-22",
"compatibility_flags": ["python_workers"],
"hyperdrive": [
{
"binding": "HYPERDRIVE",
"id": "<HYPERDRIVE_CONFIG_ID>"
}
]
}
Add "asyncpg" to dependencies in your pyproject.toml.
3. Query from a FastAPI route
Cloudflare’s documentation shows two pieces separately: FastAPI reading bindings from request.scope["env"], and asyncpg connecting through the Hyperdrive binding. Together they look like this:
import asyncpg
from fastapi import FastAPI, Request
from workers import asgi
app = FastAPI()
@app.get("/users")
async def list_users(request: Request):
hd = request.scope["env"].HYPERDRIVE
conn = await asyncpg.connect(
host=hd.host,
port=int(hd.port),
user=hd.user,
password=hd.password,
database=hd.database,
ssl=False,
)
try:
rows = await conn.fetch("SELECT id, name FROM users LIMIT 10")
finally:
await conn.close()
return [dict(r) for r in rows]
Default = asgi.entrypoint(app)
ssl=False is the value used by Cloudflare’s official Hyperdrive example. The drivers that Cloudflare tested and verified are asyncpg (recommended), pg8000, and psycopg for PostgreSQL, and aiomysql (recommended) and pymysql for MySQL.
How do I deploy Django or Flask on Cloudflare Workers?
Just like FastAPI, but with the WSGI adapter instead of ASGI, because they are synchronous frameworks:
from workers import WorkerEntrypoint, wsgi
from your_django_app.wsgi import app
Default = wsgi.entrypoint(app)
Any framework that speaks ASGI or WSGI should work the same way. Cloudflare’s python-workers-examples repository includes working projects for django, django-todo-d1, flask-todo, and fastapi-todo.
What Python packages work on Cloudflare Workers with Pyodide?
Pure Python packages published on PyPI work. Packages with C, C++, or Rust extensions only work if they publish a wheel for WebAssembly, or if they’re already included in Pyodide.
The path to more packages is PEP 783, proposed by Cloudflare. It standardizes a “PyEmscripten” platform so that maintainers can publish WebAssembly wheels on PyPI just like they do for Linux or macOS, and cibuildwheel already supports compiling them. Adoption is still early: if a dependency doesn’t have a WASM wheel, you can’t use it today.
There’s a limitation that directly affects FastAPI users. As of September 22, 2026, Hyperdrive documentation indicates that only synchronous SQLAlchemy is supported, because Python Workers doesn’t have greenlet support. If your FastAPI application uses SQLAlchemy async sessions, plan to use asyncpg directly, or synchronous SQLAlchemy by serializing operations with an asyncio.Lock, as the documentation recommends for synchronous database operations.
Cloudflare Workers or AWS Lambda for serverless Python?
The difference is in cold start, and the GA announcement doesn’t publish cold start figures.
In the Hacker News thread about the launch, the founder of Wasmer cited a benchmark from his own company, published earlier this year: around 900 ms for a minimal Python application on Cloudflare Workers, versus around 60 ms on Wasmer Edge. Wasmer sells a competing product, and he himself described the figures as several months old. One of the announcement’s authors replied that memory snapshots and request sharding have already reduced cold starts and their frequency, and pointed to Cloudflare’s own figures published in an earlier post. Both sides’ numbers are self-reported. Measure with your own application before committing a latency-sensitive API.
Where Workers clearly wins is in the operational model: no server or container image, deployment is one command, and your Python code talks to R2, D1, Queues, and Workers AI without any binding code.
What’s still missing from Python Workers?
At the time of publishing this note (September 22, 2026):
- The documentation still doesn’t say “GA”. The Python Workers page and the examples repository README still require the
python_workersflag, and the README still describes Python Workers as open beta. - The GA announcement didn’t include pricing or cold start figures.
- Async SQLAlchemy is not supported, as explained above.
Is it worth trying?
If you have a small FastAPI service, an internal API, or a webhook receiver that doesn’t depend on heavy native extensions, yes. It’s three files and two commands away from a globally deployed endpoint, and PostgreSQL through Hyperdrive is something the beta didn’t have: before, without TCP sockets, database drivers didn’t work. If your stack depends on NumPy-intensive pipelines or async SQLAlchemy, check package support first.
For the bigger picture of running backends on the edge, check out our note on edge computing for backend; for another Cloudflare piece, Browser Run; and for the context of why Python matters so much today, Python isn’t just popular: it’s leaving everyone else behind.