Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

websockets

WebSocket implementation for Python with RFC 6455 and 7692 compliance.

HTTP clients and networkingPYPI

GitHubWebsite

1. License

License from PyPI license expression.

github.com/python-websockets/websockets

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What websockets does

websockets is a Python library that does the WebSocket protocol and little else. It offers separate asyncio, threading, trio and Sans-I/O implementations, and its HTTP support stops at a health check.

websockets popularity

76 / 100
Gid Score, #170 overall
131M
downloads a week, pypi
5,746
GitHub stars
125
agent projects use it
websockets: downloads per weekPyPI, websockets 130,178,823
websockets: GitHub starspython-websockets/websockets 5,746

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How websockets is used

  • websockets is a dependency in 125 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (7.7% of the 1,623 Python ones), #7 of 126 in http clients and networking.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 1,473; those are left out of every share on this page.
  • The most used alternative in our scan is websocket-client (18 projects).
  • Projects that use it most often also use Uvicorn (72.0%), Pydantic (71.2%), FastAPI (66.4%).
  • It is more common in projects set up for Roo Code (5.4%) than for OpenAI Codex (1.9%).

By coding agent

70 projects, 2.1%
62 projects, 2.0%
51 projects, 2.1%
14 projects, 4.2%
13 projects, 2.7%
10 projects, 3.6%
9 projects, 1.9%
6 projects, 5.4%

Often used with

In 72.0% of its projects
In 71.2% of its projects
In 66.4% of its projects
In 62.4% of its projects
In 56.8% of its projects
In 55.2% of its projects
In 50.4% of its projects
In 47.2% of its projects

websockets in practice

Strengths

One library, three I/O styles

The docs show an echo server and a client for each of <code>asyncio</code>, threading and <code>trio</code>, each in its own module. The threading examples are plain blocking code with no <code>await</code>. The docs call the trio version "functionally equivalent" to the asyncio one.

A blocking client if you skip asyncio

<code>websockets.sync.client.connect</code> opens a connection inside a <code>with</code> block, and you call <code>send</code> and <code>recv</code> directly. The docs call it "a good alternative for clients, especially if you aren’t familiar with asyncio."

CI gate at 100% branch coverage

The maintainers write that the library is heavily tested for compliance with RFC 6455. They also say continuous integration fails if branch coverage drops below 100%.

Handshakes and pings are handled for you

According to the docs, the library takes care of the opening and closing handshakes, pings and pongs, and other behavior in the WebSocket specification.

Watch out for

Not an HTTP framework

The README describes its HTTP support as "just enough for an HTTP health check." If you want HTTP and WebSocket in one server, it points to uvicorn or Sanic, which build on websockets.

Coroutines, not callbacks

The README says the library was "created to provide the best coroutine-based API." It tells anyone who wants callbacks to pick another library.

The legacy asyncio module has an end date

The original <code>websockets.legacy</code> implementation was deprecated in version 14.0. The docs say it will be removed by 2030. They tell existing users to upgrade to <code>websockets.asyncio</code>, which arrived in 13.0.

Echo server with 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():
    server = await serve(echo, "localhost", 8765)
    await server.serve_forever()

asyncio.run(main())

More about websockets

Funding
  • GitHub Sponsors: https://github.com/python-websockets
  • Open Collective: https://opencollective.com/websockets
  • Tidelift: https://tidelift.com/funding/github/pypi/websockets
  • 2 GitHub sponsors

See all

Packages around it
  • requests: HTTP client
  • python-dotenv: .env config loader
  • solders: Solana types
  • pydantic: data validation
  • solana: Solana Python SDK
  • anyio: async compatibility layer
More in HTTP clients and networking

Alternatives

websockets This page

BSD-3-ClauseGid 76131M/wk

websocket-client

WebSocket client library for Python with low-level API options.

Apache-2.0Gid 6941.6M/wk

Compare websockets with another tool

Get started

Install it.

pip install websockets

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## websockets
- For asyncio code, import from `websockets.asyncio.server` and `websockets.asyncio.client`.
- If a project uses `websockets.legacy`, upgrade it to `websockets.asyncio`. The docs say legacy was deprecated in 14.0 and will be removed by 2030.
- For blocking code, use `websockets.sync.client.connect` inside a `with` block. Use `websockets.sync.server` only for servers that don't handle many client connections.
- In Trio projects, use the `websockets.trio.server` and `websockets.trio.client` modules.
- Don't implement handshakes, pings or pongs yourself. Call `send` and `recv`, or iterate with `async for message in websocket`.
- Don't add HTTP routes to a websockets server. Its HTTP support only covers a health check, so use uvicorn or Sanic when one server must serve both.
- Don't look for a callback API. The README says to pick another library if you need one.