websocket-client

A low-level, dependency-free WebSocket client for Python supporting both synchronous and event-driven connections.

Library
PyPI
v1.9.2
3,708 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
65 /100 Good
Development Activity 56
Maintenance 36
Community 68
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
79 /100 Good
Architecture 78
Code Quality 84
Innovation 65
Learning Curve 90

websocket-client is a pure-Python WebSocket client library implementing the RFC 6455 (hybi-13) protocol with zero required dependencies. It exposes both a low-level WebSocket class for direct socket-level control and a higher-level WebSocketApp that mirrors the JavaScript WebSocket API with callback-based event handling (on_open, on_message, on_error, on_close).

Widely used as a standard choice for WebSocket connectivity in Python — from IoT device clients to market-data feeds to internal service tooling — the library has been maintained continuously since 2010, with the current maintainer team shipping regular releases, SSL/TLS and proxy support, automatic reconnection, and optional performance and testing extras via pip extras.

What You Get

  • A low-level WebSocket class exposing connect, send, recv, and close for direct protocol control
  • A WebSocketApp class mirroring the browser WebSocket API with on_open/on_message/on_error/on_close callbacks
  • Built-in SSL/TLS support plus HTTP/SOCKS proxy connection handling via _http.py
  • Automatic reconnection support via run_forever(dispatcher=..., reconnect=N) when paired with a dispatcher like rel
  • Optional wsaccel and python-socks extras for UTF-8 validation speedups and proxy support

Common Use Cases

  • Real-time market data feeds - trading and fintech developers use WebSocketApp.run_forever with automatic reconnect to maintain always-on connections to exchange data streams
  • IoT and device telemetry - device integrators embed the low-level WebSocket class to send/receive framed messages over constrained network links without pulling in async framework dependencies
  • Internal service-to-service push channels - backend engineers use the library for lightweight, synchronous WebSocket clients in scripts and services that don’t require an async event loop
  • Debugging and manual protocol testing - the bundled wsdump CLI utility (_wsdump.py) lets developers connect to and inspect a WebSocket endpoint interactively from the terminal

Under The Hood

Architecture The library separates protocol framing (_abnf.py, implementing RFC 6455 frame parsing), low-level socket handling (_core.py, the WebSocket class managing connect/send/recv over raw sockets), HTTP handshake and proxy tunneling (_http.py, _handshake.py), and a higher-level event-driven wrapper (_app.py, the WebSocketApp class) that composes the core WebSocket internally and drives it through a run_forever loop with pluggable dispatchers (_dispatcher.py) for reconnect and async-runtime integration. This is a modular, layered design — protocol layer, transport layer, handshake layer, then a high-level app layer — with __init__.py re-exporting the public surface via wildcard imports. Because both WebSocket and WebSocketApp ultimately depend on the same frame_buffer/continuous_frame primitives in _abnf.py, changes to core framing logic ripple through both API levels.

Tech Stack Pure Python 3.10+, with zero required runtime dependencies — install_requires is empty, relying entirely on the standard library’s socket, ssl, threading, and struct modules. Optional extras cover python-socks and wsaccel for proxy support and a C-accelerated UTF-8 validation/masking speedup, websockets for running the test suite’s local echo server, and Sphinx/sphinx_rtd_theme/myst-parser for documentation builds. Packaging uses setuptools>=77 via a pyproject.toml build-backend paired with a setup.py carrying the actual package metadata. Static typing is enforced separately through mypy.ini, targeting the websocket/ package while excluding tests and the _wsdump.py CLI tool. CI runs dedicated GitHub Actions workflows for linting, building, doctests, and code coverage via Codecov.

Code Quality An extensive test suite lives under websocket/tests/, spanning ABNF framing, app-level behavior, cookiejar handling, dispatcher logic, handshake edge cases, HTTP, large payloads, logging helpers, reconnect-on-bad-fd scenarios, socket bugs, SSL compatibility and edge cases, URL parsing, and general utilities — run with pytest. Core modules carry typed function signatures throughout (Optional/Union/Callable annotations in _core.py and _app.py) and are checked with mypy in CI. A custom exception hierarchy in _exceptions.py (WebSocketException, WebSocketProtocolException, WebSocketConnectionClosedException, WebSocketTimeoutException) gives callers granular error handling instead of bare exceptions, and code formatting follows the black style declared in the README.

API Design The library’s central developer-experience choice is offering two coexisting API levels under one import: a low-level WebSocket class for raw send/recv/close control, and a WebSocketApp deliberately modeled on the browser’s JavaScript WebSocket object so web developers can transfer intuition directly. A zero-required-dependency footprint keeps integration friction minimal, and optional extras are cleanly namespaced (pip install websocket-client[optional], [test], [docs]). It doesn’t extend the protocol itself — WebSocket Compression (RFC 7692) is explicitly unsupported — but the dual-API ergonomics and dependency-free design are its clearest differentiator against async-first alternatives like websockets or aiohttp.

Used by 9 apps in this directory

Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,644

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

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated today
Go
82%
AGPL 3.0

Beta9

AI Development · Automation · Data Engineering

1,808

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
66
Dependency
Built with
Go 82%
Python 17%
Updated yesterday
C++
68%
Apache 2.0

ClickHouse

Analytics · Data Engineering · Databases

50,322

Open-source column-oriented database that delivers real-time analytical queries on petabyte-scale data with millisecond latency.

View details
95
Repo Health
90
Technical
64
Dependency
Built with
C++ 68%
Python 13%
Updated today
Python
100%
GPL 3.0

ComfyUI

AI Design Tools · AI Development

136,669

The most powerful node-based AI workflow engine for creating images, video, 3D models, and audio with full control over every generation step.

View details
92
Repo Health
81
Technical
75
Dependency
Built with
Python 100%
Updated today
JavaScript
54%
MIT

GPU Hot

Devops · Monitoring

1,636

Real-time NVIDIA GPU monitoring dashboard — self-hosted, scale from 1 to 100+ GPUs with sub-second metrics and no cloud dependency.

View details
58
Repo Health
73
Technical
79
Dependency
Built with
JavaScript 54%
Python 34%
Updated 1 months ago
TypeScript
55%
Other

Jaaz

AI Agents · AI Design Tools

6,698

Open-source AI creative agent that turns visual sketches and canvas gestures into images and videos — no text prompts required.

View details
46
Repo Health
59
Technical
71
Dependency
Built with
TypeScript 55%
Python 34%
JavaScript 10%
Updated 7 months ago
Python
64%
Other

Keep

Automation · Devops · Monitoring

12,381

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
87
Repo Health
79
Technical
66
Dependency
Built with
Python 64%
TypeScript 36%
Updated 1 weeks ago
Python
52%
Other

Odoo

CRM · ERP · Productivity

54,954

The open source ERP platform that integrates CRM, accounting, inventory, manufacturing, and 60+ business apps into one seamlessly connected suite.

View details
87
Repo Health
82
Technical
64
Dependency
Built with
Python 52%
JavaScript 43%
Updated today
Python
74%
AGPL 3.0

OpenViking

AI Development · AI Memory · Databases

39,552

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 74%
Rust 12%
TypeScript 11%
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