FastAPI · Cloudflare Workers docs | Latest TMZ Celebrity News & Gossip | Watch TMZ Live Skip to content
Cloudflare Docs

FastAPI

The FastAPI package is supported in Python Workers.

FastAPI applications use a protocol called the Asynchronous Server Gateway Interface (ASGI). This means that FastAPI never reads from or writes to a socket itself. An ASGI application expects to be hooked up to an ASGI server, typically uvicorn. The ASGI server handles all of the raw sockets on the application’s behalf.

The Workers runtime provides an ASGI server directly to your Python Worker, which lets you use FastAPI in Python Workers.

Get Started

Clone the cloudflare/python-workers-examples repository and run the FastAPI example:

Terminal window
git clone https://github.com/cloudflare/python-workers-examples
cd python-workers-examples/03-fastapi
npx wrangler@latest dev

Example code

from fastapi import FastAPI, Request
from pydantic import BaseModel
async def on_fetch(request, env):
import asgi
return await asgi.fetch(app, request, env)
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello, World!"}
@app.get("/env")
async def root(req: Request):
env = req.scope["env"]
return {"message": "Here is an example of getting an environment variable: " + env.MESSAGE}
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float | None = None
@app.post("/items/")
async def create_item(item: Item):
return item
@app.put("/items/{item_id}")
async def create_item(item_id: int, item: Item, q: str | None = None):
result = {"item_id": item_id, **item.dict()}
if q:
result.update({"q": q})
return result
@app.get("/items/{item_id}")
async def read_item(item_id: int):
return {"item_id": item_id}

TMZ Celebrity News – Breaking Stories, Videos & Gossip

Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

🎥 Watch TMZ Live

TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.