websockets: A Python Library for WebSocket Servers and Clients
This repository profile is provided by osrepos.com, an open source repository discovery platform.
Summary
websockets is a robust Python library designed for building WebSocket servers and clients with a focus on correctness, simplicity, robustness, and performance. It leverages Python's `asyncio` framework for an elegant coroutine-based API, also offering `threading` and Sans-I/O implementations. This library provides a reliable foundation for real-time communication in Python applications.
Repository Information
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Introduction
websockets is a robust Python library designed for building WebSocket servers and clients. It emphasizes correctness, simplicity, robustness, and performance, providing an elegant coroutine-based API built on Python's standard asynchronous I/O framework, asyncio. It also offers threading and Sans-I/O implementations for different use cases.
Installation
To get started with websockets, you can install it using pip:
pip install websockets
Examples
Here's an echo server using the asyncio API:
#!/usr/bin/env python
import asyncio
from websockets.asyncio.server import serve
async def echo(websocket):
async for message in websocket:
await websocket.send(message)
async def main():
async with serve(echo, "localhost", 8765) as server:
await server.serve_forever()
asyncio.run(main())
And here's how a client sends and receives messages with the threading API:
#!/usr/bin/env python
from websockets.sync.client import connect
def hello():
with connect("ws://localhost:8765") as websocket:
websocket.send("Hello world!")
message = websocket.recv()
print(f"Received: {message}")
hello()
Why use websockets?
The websockets library is developed with four core principles in mind:
- Correctness:
websocketsis heavily tested for compliance with RFC 6455. Continuous integration ensures 100% branch coverage. - Simplicity: It offers a straightforward API, allowing developers to focus on application logic while it manages connections.
- Robustness: Built for production environments,
websocketsis known for correctly handling backpressure, a critical aspect in asynchronous programming. - Performance: Memory usage is optimized and configurable. A C extension accelerates expensive operations, pre-compiled for Linux, macOS, and Windows, and packaged in the wheel format for each system and Python version.
Links
Find more information and contribute to the websockets project:
Related repositories
Similar repositories that may be relevant next.

Tornado: A Powerful Python Web Framework and Asynchronous Library
July 23, 2026
Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. It utilizes non-blocking I/O to efficiently handle tens of thousands of open connections. This makes it an ideal choice for applications requiring long-lived connections, such as long polling, WebSockets, and real-time services.

Autobahn|Python: WebSocket & WAMP for Real-Time Python Applications
July 22, 2026
Autobahn|Python is a robust open-source library providing WebSocket and WAMP implementations for Python 3.11+. It enables developers to build real-time applications with bidirectional messaging, remote procedure calls, and publish-subscribe patterns, seamlessly integrating with Twisted and asyncio frameworks.

Gunicorn: A Fast and Lightweight WSGI HTTP Server for Python
July 22, 2026
Gunicorn, or 'Green Unicorn', is a robust and widely-used WSGI HTTP server for Python applications, known for its speed and efficiency. It employs a pre-fork worker model, making it compatible with various web frameworks like Django and Flask. This server is designed to be light on server resource usage while providing reliable performance for your Python web projects.

Werkzeug: A Comprehensive WSGI Web Application Library for Python
July 22, 2026
Werkzeug is a comprehensive WSGI web application library, providing essential tools for building web applications in Python. It includes an interactive debugger, robust request and response objects, a flexible routing system, and various HTTP utilities. This powerful library serves as the foundation for popular frameworks like Flask, offering developers significant flexibility without enforcing specific dependencies.
Source repository
Open the original repository on GitHub.
10 counted GitHub visits