websockets

Build correct, fast WebSocket servers and clients in Python with asyncio, threading, or Sans-I/O APIs.

Library
PyPI
v17.3
5,736 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
91 /100 Excellent
Development Activity 100
Maintenance 84
Community 80
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
91 /100 Excellent
Architecture 91
Code Quality 93
Innovation 90
Learning Curve 88

websockets is a Python library for building WebSocket servers and clients with a focus on correctness, simplicity, robustness, and performance. Its default implementation is built on asyncio and exposes an elegant coroutine-based API, while additional threading and Sans-I/O implementations let you integrate WebSockets into any concurrency model.

Heavily tested for compliance with RFC 6455 and RFC 7692, websockets enforces 100% branch coverage in CI and ships a C extension with prebuilt wheels for fast, memory-efficient production deployments. All you need to remember is await ws.recv() and await ws.send(msg) — the library manages connections, ping/pong keepalives, backpressure, and clean closes for you.

What You Get

  • An asyncio implementation with a coroutine-based serve/connect API and async iteration over incoming messages
  • A synchronous threading implementation for scripts and codebases that do not use asyncio
  • A Sans-I/O core (websockets.protocol) you can drive from any I/O framework
  • A C speedups extension with prebuilt wheels for Linux, macOS, and Windows across Python versions
  • Built-in permessage-deflate compression, basic-auth helpers, proxy support, and a websockets CLI client

Common Use Cases

  • Serving realtime updates to browser or mobile clients over a persistent WebSocket connection
  • Writing a WebSocket client to consume a streaming API or exchange feed
  • Building the WebSocket transport layer underneath higher-level frameworks such as uvicorn or Sanic
  • Bridging services with low-latency bidirectional messaging without polling

Under The Hood

Architecture — websockets is organized around a Sans-I/O core: src/websockets/protocol.py together with client.py and server.py implement the RFC 6455 state machine as pure functions over bytes and events, entirely decoupled from any I/O. Concrete transports wrap this core — src/websockets/asyncio/ provides the asyncio Connection, ServerConnection, and ClientConnection classes plus serve/connect, src/websockets/sync/ provides the threading equivalents, and src/websockets/legacy/ retains the previous asyncio implementation for compatibility. Framing, headers, URIs, and HTTP/1.1 handshake handling are factored into dedicated modules (frames.py, headers.py, uri.py, http11.py), and the public surface is re-exported lazily via imports.lazy_import in __init__.py. Tech Stack — Pure Python (requires Python >=3.11) built on the standard-library asyncio and threading modules with no runtime third-party dependencies; an optional C extension (speedups.c) accelerates frame masking and is shipped as prebuilt wheels via cibuildwheel. Packaging uses setuptools with configuration in pyproject.toml, and the project ships a py.typed marker for full type-checker support. Code Quality — Exceptionally strong: 59 test modules under tests/ mirror the source layout, CI fails under 100% branch coverage, and the codebase is fully type-annotated with from __future__ import annotations and precise typing throughout. Naming is consistent, docstrings are thorough, and error handling is modeled by a dedicated exceptions.py hierarchy (ConnectionClosed, InvalidHandshake, and friends). API Design — The public API is deliberately minimal and ergonomic: async with serve(handler, host, port) for servers, async with connect(uri) for clients, and just send/recv plus async iteration for messages. The same conceptual API is mirrored across the asyncio and threading implementations, documentation on Read the Docs is a first-class concern with a tutorial and reference, and connection management, backpressure, and keepalive are handled automatically so little boilerplate is required.

Used by 30 apps in this directory

Python
45%
GPL 3.0

MaxKB

AI Development · Knowledge Management

23,022

Build enterprise-grade AI agents with RAG, workflows & multi-modal support

View details
92
Repo Health
68
Technical
66
Dependency
Built with
Python 45%
Vue 37%
TypeScript 17%
Updated 1 weeks ago
TypeScript
92%
Other

n8n

Automation · No Code Platforms

208,437

Code when you need it, UI when you don't — the workflow automation platform built for technical teams who refuse to choose.

View details
95
Repo Health
87
Technical
62
Dependency
Built with
TypeScript 92%
Updated 1 weeks ago
Python
100%
Other

OpenBB

Analytics · Databases · Invoicing Finance

74,601

The AI Workspace for Finance: Connect Data, Run AI Agents, Build Analytics

View details
80
Repo Health
80
Technical
65
Dependency
Built with
Python 100%
Updated 1 weeks ago
Python
100%
MIT

opennews-mcp

AI Agents · Developer Tools · Mcp

2,418

An MCP server that plugs AI agents into 85+ real-time crypto and finance news feeds, complete with AI impact scores, trading signals, and live WebSocket updates.

View details
44
Repo Health
62
Technical
76
Dependency
Built with
Python 100%
Updated 1 months ago
Python
39%
Apache 2.0

OpenSandbox

Developer Tools · Security

16,116

Secure, fast, and extensible sandbox runtime for AI agents with multi-language SDKs and Docker/Kubernetes runtimes.

View details
85
Repo Health
81
Technical
70
Dependency
Built with
Python 39%
Go 36%
Updated 6 days ago
Python
73%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

40,705

An open-source context database that gives AI agents a unified filesystem for memory, resources, and skills with hierarchical tiered retrieval.

View details
85
Repo Health
75
Technical
64
Dependency
Built with
Python 73%
TypeScript 12%
Rust 11%
Updated 6 days ago
TypeScript
58%
MIT

pad.ws

Collaboration · Design Tools

4,206

A browser-based whiteboard that doubles as a full development environment, letting you draw and code in the same canvas.

View details
37
Repo Health
61
Technical
78
Dependency
Built with
TypeScript 58%
Python 31%
SCSS 10%
Updated 1 years ago
Python
49%
Other

Arize Phoenix

Analytics · Devops · Monitoring

11,976

Open-source AI observability platform for tracing, evaluating, and debugging LLM applications with built-in intelligence and MCP support.

View details
92
Repo Health
88
Technical
67
Dependency
Built with
Python 49%
TypeScript 43%
Updated 6 days ago
Python
99%
Apache 2.0

Rasa Open Source

AI Assistants · AI Development · Voice AI

21,353

Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.

View details
62
Repo Health
78
Technical
63
Dependency
Built with
Python 99%
Updated 3 months ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers