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.

ctx-gate: LLM Context Gateway for Efficient Token Usage
September 16, 2026
ctx-gate is an LLM-agnostic context optimization proxy that reduces token consumption in AI interactions. It intelligently prunes conversation history and tool outputs, ensuring critical facts are retained without altering your workflow. Compatible with Anthropic and OpenAI APIs, ctx-gate helps developers manage LLM costs and maintain prompt fidelity.
Ferret MCP: AI-Powered Knowledge Extraction for Any Codebase
September 14, 2026
Ferret MCP is an MCP server designed to extract comprehensive knowledge from any codebase, combining static analysis with AI-powered deep interpretation. It provides detailed insights into architecture, patterns, dependencies, and API surface, delivering a senior engineer's analysis in seconds. This tool integrates seamlessly with various MCP clients, offering both free static analysis and advanced AI-driven reports.
Local LLM Linux Troubleshoot: An AI Agent for Linux Diagnostics
September 14, 2026
Local LLM Linux Troubleshoot is an AI-powered agent designed to diagnose and resolve issues on Linux systems. It leverages llama.cpp for local AI processing, offering system diagnostics, safe command execution, and support for Docker, CLI, and a web GUI. This tool provides a privacy-first approach to managing and troubleshooting your Linux environment.

OpenWorkProof: Verifiable Work Contracts for AI Agent Systems
September 13, 2026
OpenWorkProof is an open protocol designed to bring transparency and accountability to AI agent work. It establishes verifiable contracts for multi-agent systems, ensuring that tasks are authorized, executed within agreed scopes, and independently verifiable. This protocol addresses critical questions about authorization, execution evidence, and human acceptance in AI-driven workflows.
Source repository
Open the original repository on GitHub.
22 counted GitHub visits