Catalog / Vercel

Routing Middleware now supports Python

todayaddedOriginal notes

You can now write routing middleware in Python for FastAPI, Flask, Django, and other Python frameworks. It runs before requests reach your app, and can rewrite, redirect, or answer them.

To set it up, point the proxy entrypoint in vercel.toml at your proxy:

Your middleware is an ASGI or WSGI app that runs separately from your main app, with only the packages in the vercel.proxy dependency group of your pyproject.toml. Add the packages your middleware imports to that group:

The vercel-proxy package provides utilities for writing routing middleware on Vercel, including a Proxy app that routes requests by path:

Requests that match no route continue to your app unchanged.

For more information, see the Routing Middleware Python reference.

Read more