Vercel — AI · · 1 min read

WebSocket support is now available for Python Functions

Mirrored from Vercel — AI for archival readability. Support the source by reading on the original site.

Vercel now supports WebSocket connections for Python applications.

WebSockets enable bidirectional communication between client- and server-side code, powering real-time features like interactive AI streaming, real-time chat, and multiplayer live collaboration. Both ASGI and WSGI applications are supported, including frameworks like FastAPI, Django, and Flask.

app.py
import fastapi
app = fastapi.FastAPI()
@app.websocket("/api/ws")
async def websocket_endpoint(websocket: fastapi.WebSocket):
await websocket.accept()
try:
while True:
message = await websocket.receive_text()
await websocket.send_text(message)
except fastapi.WebSocketDisconnect:
pass

Python WebSocket server using FastAPI, deployed as a Vercel Function

Explore the FastAPI AI Chat and Flask AI Chat examples, or read the WebSockets documentation to get started.

Contributors

Eric Dodds

Discussion (0)

Sign in to join the discussion. Free account, 30 seconds — email code or GitHub.

Sign in →

No comments yet. Sign in and be the first to say something.

More from Vercel — AI