websockets is a Python package for building WebSocket servers and clients with asyncio, threading, trio, or Sans-I/O layers.
Overview
The websockets library implements RFC 6455 for Python with a focus on correctness, simple APIs, and production robustness. The default asyncio implementation exposes coroutine helpers such as recv and send while managing connection lifecycle details internally.
Parallel implementations cover synchronous threading, trio, and a Sans-I/O core for third-party integration. The project documents feature matrices explaining which capabilities each backend supports.
Design goals include heavy compliance testing, sensible backpressure behavior, and optimized performance through optional C extensions shipped as wheels. Documentation on Read the Docs covers tutorials, migration from the legacy asyncio module, and enterprise support options.
It intentionally keeps HTTP support minimal, focusing on being a dedicated WebSocket stack rather than a general web framework.
Key features
- asyncio server and client API
- threading and trio variants
- Sans-I/O integration layer
- RFC 6455 compliance testing
- C-accelerated hot paths
- Legacy migration path documented
Use cases
- Python realtime web backends
- Bridge services speaking WebSocket
- Embedding WebSockets in larger Python apps