I built a small Python library to improve WebSocket connection stability in FastAPI apps.
fastapi-websocket-stabilizer wraps FastAPI’s native WebSocket with automatic heartbeat (ping/pong) handling to reduce unexpected disconnects caused by idle timeouts or unstable networks. It’s lightweight, easy to integrate, and focused only on keeping long-lived WebSocket connections reliable—no full real-time framework, no extra abstractions.
I built this after repeatedly reimplementing keepalive logic across multiple FastAPI projects. The goal is to encapsulate that logic in a minimal, reusable way. Removal is straightforward if you decide not to use it later.
GitHub:
https://github.com/yuuichieguchi/fastapi-websocket-stabilize...
PyPI:
https://pypi.org/project/fastapi-websocket-stabilizer/
Feedback welcome, especially from people running WebSocket-heavy FastAPI services.