Menu

Routing Middleware now supports Python - Vercel
📰

Routing Middleware now supports Python - Vercel

Vercel News·Daniel Park·5 days ago
#HvRYht9k
#vercel#proxy#request#middleware#slug
Reading 0:00
15s threshold

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:

[ proxy ]

entrypoint = "proxy: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:

uv add --group vercel.proxy vercel-proxy

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

from urllib . parse import quote

from vercel . proxy import ContinueResponse , Proxy , RedirectResponse , Request , Response

proxy = Proxy ( )

@proxy . route ( "/old-blog/{slug}" )

def old_blog ( request : Request ) - > Response :

slug = quote ( request .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.