# websockets — card for AI agents

WebSocket implementation for Python with RFC 6455 and 7692 compliance.

Category: HTTP clients and networking · PyPI package `websockets` · latest version 17.4 (checked 2026-11-01)
Install: `pip install websockets`
License: BSD-3-Clause (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (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.

## What it is
- websockets is a Python library for building WebSocket servers and clients. The README says it focuses on "correctness, simplicity, robustness, and performance." It aims to implement RFC 6455, the WebSocket protocol, and RFC 7692, which covers compression extensions. The repository dates from 2013-03-30 and is BSD-3-Clause licensed.
- The default implementation is built on `asyncio` and gives a coroutine-based API. Two more implementations sit in their own modules: `websockets.sync` for threading and `websockets.trio`. A Sans-I/O implementation is meant for third-party libraries, typically application servers. The docs say the newer asyncio implementation builds on that Sans-I/O layer. They also say the library handles the opening and closing handshakes and pings and pongs for you.
- The docs call the asyncio version "ideal for servers that handle many client connections." They call the threading version a good alternative for clients and for servers with few connections. The README says it is not a fit if you want callbacks, or one server that speaks both HTTP and WebSocket.

## Caveats
- 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 `websockets.legacy` implementation was deprecated in version 14.0. The docs say it will be removed by 2030. They tell existing users to upgrade to `websockets.asyncio`, which arrived in 13.0.
- Threading server is for light loads: On the server side, the docs limit the threading implementation to servers that "don’t handle too many client connections."

## Numbers (AgentGid data)
- Gid Score: 76.3 (#170 of all tools, 11 of 126 in its category)
- Used in 125 public projects set up for AI coding agents (2.0%)
- Downloads last week: 131,227,567 (as of 2026-11-24), +15.2% over 4 weeks
- GitHub stars: 5,746 (as of 2026-11-24)
- Last push: 2026-11-14

## Often used with
Uvicorn 72.0%, Pydantic 71.2%, FastAPI 66.4%, python-dotenv 62.4%, PyYAML 56.8%, Requests 55.2%

## Checked alternatives (same job)
- websocket-client: https://agentgid.com/tools/websocket-client/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/websockets/
- Homepage: https://github.com/python-websockets/websockets
- Repository: https://github.com/python-websockets/websockets
- Source: https://github.com/python-websockets/websockets#readme
- Source: https://github.com/python-websockets/websockets
- Source: https://github.com/python-websockets/websockets/releases
- Source: https://websockets.readthedocs.io/

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
