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.

Maskit: Local Privacy Gateway for LLMs and AI Tools
September 20, 2026
Maskit is a local privacy desensitization gateway engineered for large language models and AI tools. It automatically masks sensitive data in requests sent to AI services and then seamlessly restores it in streaming responses, ensuring private information remains local. This innovative solution supports various AI assistants like Cursor and Claude Code, along with any tool offering a configurable Base URL.

CyberVerse: Self-Hosted Real-Time Digital Human Agent Platform
September 18, 2026
CyberVerse is an open-source, self-hosted platform for building real-time digital human agents. It leverages WebRTC, persona memory, tools, and RAG to create voice-first AI agents, with optional digital-human video capabilities. This powerful framework allows developers to create highly interactive and lifelike AI companions.

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.
Source repository
Open the original repository on GitHub.
22 counted GitHub visits