FastAPI is supported in Python Workers. The Python Workers provide an ASGI server that lets developers use FastAPI directly in a Python Worker.

To get started with FastAPI in Python Workers, set compatibility_date to a recent date and enable the python_workers compatibility flag in wrangler.jsonc.

Developers can serve any static frontend alongside a FastAPI backend by using Workers Static Assets. This is equivalent to FastAPI’s native app.mount() method for serving a static build directory as low-priority routes, but on Workers the static assets are served from Cloudflare’s globally distributed asset store through the ASSETS binding.

With this setup, a request to /api/hello is handled by FastAPI, while a request to /index.html or any other unmatched path is served from the public directory through the assets binding.