
WebSocket support is now available for Python Functions
Quick Answer
Vercel now enables WebSocket connections for Python applications, supporting real-time features in frameworks like FastAPI, Django, and Flask.
Quick Take
This allows bidirectional communication, enhancing interactive AI streaming and collaboration capabilities for developers deploying on Vercel Functions.
Key Points
- WebSocket support enhances real-time communication in Python applications.
- Compatible with ASGI and WSGI frameworks including FastAPI, Django, and Flask.
- Enables features like interactive AI streaming and real-time chat.
- Example provided for a Python WebSocket server using FastAPI.
- Documentation available for further exploration of WebSocket capabilities.
📖 Reader Mode
~1 min readVercel 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.
— Originally published at vercel.com
Want this in your inbox every morning?
Daily brief at your local 8am — bilingual EN/中文, free.
More from Vercel AI
See more →
The Agent Stack
The Agent Stack by Vercel AI provides essential building blocks for creating production-grade agents, enabling seamless integration across multiple AI models and secure operations. It features components like AI Gateway for model routing, Workflow SDK for durable execution, and Vercel Connect for scoped access, streamlining agent development and deployment across various platforms.

