Vercel routing middleware now works with Python apps
A new vercel-proxy package lets FastAPI, Flask and Django projects rewrite, redirect or tag requests before they reach the app, something only JavaScript middleware could do before.
Vercel said on 21 October that routing middleware, the code that runs before a request reaches your app, now works with Python as well as JavaScript. A new vercel-proxy package adds routing for FastAPI, Flask, Django and other Python frameworks, matching what JS middleware has done on Vercel for years.
You point a vercel.toml file at the proxy with entrypoint = "proxy:proxy". The proxy runs as its own ASGI or WSGI app, separate from your main one, with path-based routing but no subrouters, mounts or static files. A route can return a RedirectResponse to send old URLs somewhere new, or a ContinueResponse to pass the request through with extra headers attached:
from vercel.proxy import Proxy, RedirectResponse, ContinueResponse, Request, Response
proxy = Proxy()
@proxy.route("/old-blog/{slug}")
def old_blog(request: Request) -> Response:
return RedirectResponse(f"/blog/{request.path_params['slug']}", status_code=308)
Why it matters: Python frameworks on Vercel had no equivalent to JS Edge Middleware for rewrites, redirects or header injection ahead of the app. Anyone running FastAPI, Flask or Django on Vercel can now handle that routing logic directly, without standing up a separate reverse proxy just to redirect a URL or stamp a header.