Build a real-time chat server where both the server and the browser can send messages to each other at any moment without the browser having to ask first.
Create a live dashboard that pushes updated data to connected browsers the instant it changes, without polling.
Add real-time multiplayer features to a game or collaborative tool by keeping a persistent connection open between players and the server.
Build a financial ticker that streams price updates to thousands of connected clients simultaneously.
Install with pip, no external services required, but you need Python with asyncio knowledge to get the most out of the primary API.
This is a Python library for building real-time two-way connections between a server and a client, using a communication standard called WebSocket. The standard web model works like a conversation where the client speaks first every time: your browser asks for a page, the server responds, and the connection closes. WebSocket flips this so both sides can send messages to each other at any moment, which is what makes things like chat applications, live dashboards, multiplayer games, and financial tickers possible on the web. The websockets library handles all the low-level work of opening, maintaining, and closing these connections so that a developer can focus on what to do with the messages rather than the plumbing underneath. The primary way to use it is through Python's asyncio system, which lets a single program manage many simultaneous connections without using a separate thread for each one. For developers who prefer a simpler threading-based approach, there is also a synchronous API that works without async/await syntax. The project is built around four stated priorities: following the WebSocket specification precisely, keeping the API as simple as possible to read and write, handling edge cases that trip up other libraries in production (the README specifically mentions an issue called backpressure that most other WebSocket libraries handled incorrectly), and running efficiently with optimized memory use and a compiled C extension for the parts of the protocol that are computationally expensive. The library is intentionally focused only on WebSocket, not on general HTTP. If you need a server that handles both HTTP routes and WebSocket connections in the same codebase, the README points you toward other tools (like uvicorn or Sanic) that build on top of this library to add that combination. It is released under the BSD license and commercial support is available through Tidelift.
← python-websockets on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.