websockets

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

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

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
91/100Excellent
Development Activity100
Maintenance84
Community80
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
91/100Excellent
Architecture91
Code Quality93
Innovation90
Learning Curve88

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 28 apps in this directory

Python
100%
Apache 2.0

Agno

Devops · AI Development · Automation

41,774

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
67
Dependency
Built with
Python100%
Updated today
Python
62%
MIT

AutoGen

AI Development · Automation

60,518

Build autonomous and human-in-the-loop multi-agent AI systems with a layered, event-driven Python and .NET framework pioneered at Microsoft Research.

View details
57
Repo Health
78
Technical
75
Dependency
Built with
Python62%
C#25%
TypeScript12%
Updated 4 months ago
Python
68%
Other

AutoGPT

Automation · Productivity · AI Assistants

186,687

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
67
Dependency
Built with
Python68%
TypeScript31%
Updated today
Python
68%
Other

Baserow

No Code Platforms · Databases

5,635

Open-source no-code platform to build databases, apps, automations, and AI agents — self-hosted or cloud, with full data ownership.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Python68%
JavaScript15%
Vue12%
Updated today
Go
82%
AGPL 3.0

Beta9

Developer Tools · AI Development · Data Engineering

1,746

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
85
Repo Health
78
Technical
69
Dependency
Built with
Go82%
Python17%
Updated today
Go
42%
Apache 2.0

e2a

AI Agents · Automation

182

Give your AI agents a real, authenticated email address — with SPF/DKIM-verified inbound, HMAC-signed delivery, WebSocket fan-out, and human-in-the-loop approval built in.

View details
78
Repo Health
80
Technical
76
Dependency
Built with
Go42%
TypeScript28%
Python15%
Updated today
TypeScript
75%
Apache 2.0

Fern

Developer Tools

3,761

Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.

View details
90
Repo Health
86
Technical
67
Dependency
Built with
TypeScript75%
Updated today
TypeScript
72%
AGPL 3.0

Firecrawl

AI Development · Developer Tools

169,311

Turn any website into clean, LLM-ready data with a single API call — no proxy headaches, no scraping complexity.

View details
89
Repo Health
83
Technical
66
Dependency
Built with
TypeScript72%
Python14%
Updated today
Python
64%
MIT

Flowfile

Data Engineering

341

Visual ETL that compiles to Polars — build pipelines on a canvas, export as standalone Python, and run anywhere without platform lock-in.

View details
83
Repo Health
81
Technical
66
Dependency
Built with
Python64%
Vue19%
TypeScript16%
Updated today

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

Search