Python WebSocket libraries

Updated Nov 2026

Python WebSocket libraries open long-lived, two-way connections between a client and a server. A connection starts as an HTTP request and then carries messages in both directions until either side closes it. These libraries let chat apps, live dashboards, and AI agents stream data without polling.

Popularity

websockets has the most monthly downloads among the dedicated WebSocket libraries in this comparison, at 539.1M.

LibraryMonthly downloadsStarsLast releaseLicense
Starlette
706.4M
12.7KOct 2026BSD-3-Clause
aiohttp
562.2M
16.6KOct 2026Apache-2.0 AND MIT
websockets
539.1M
5.7KOct 2026BSD-3-Clause
websocket-client
185.6M
3.7KAug 2026Apache-2.0
Tornado
122.3M
22.2KNov 2026Apache-2.0
wsproto
74.9M
303Nov 2025MIT
simple-websocket
28.7M
90Oct 2024MIT
Trio WebSocket
27.8M
81Feb 2025MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Provides a small ASGI library.

Downloads / mo
706.4M
Stars
12.7K
Last release
1.10.0
License
BSD-3-Clause

Quickstart

From websockets.md
$ python3 -m pip install starlette
from starlette.websockets import WebSocket
async def app(scope, receive, send):
    websocket = WebSocket(scope=scope, receive=receive, send=send)
    await websocket.accept()
    await websocket.send_text('Hello, world!')
    await websocket.close()

Starlette examples

From open-source projects on GitHub

Provides an asyncio HTTP client and server framework.

Downloads / mo
562.2M
Stars
16.6K
Last release
3.14.5
License
Apache-2.0 AND MIT

Quickstart

From client_quickstart.html
$ python3 -m pip install aiohttp
import asyncio
import aiohttp
async def main():
    async with aiohttp.ClientSession() as session:
        async with session.ws_connect('ws://localhost:8765') as ws:
            await ws.send_str('hello')
asyncio.run(main())

aiohttp examples

From open-source projects on GitHub

Builds WebSocket servers and clients in Python.

Downloads / mo
539.1M
Stars
5.7K
Last release
17.4
License
BSD-3-Clause

Strengths

  • Offers async and threaded interfaces. Choose a coroutine-based or threaded connection API for the application.
  • Retries transient connection failures. Use the asynchronous connect iterator for reconnects with exponential backoff.

Limitations

  • Receives must stay serialized. Have one coroutine receive messages from each connection at a time.
  • Directly awaited connections need closing. Close a directly awaited connection when the application finishes using it.

Quickstart

From README.rst
$ python3 -m pip install websockets
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())

websockets examples

From open-source projects on GitHub

websocket-client

Provides low-level WebSocket client APIs and callback-based long-lived connections.

Downloads / mo
185.6M
Stars
3.7K
Last release
1.9.2
License
Apache-2.0

Strengths

  • Handles long-lived callback connections. Attach message, error, and close callbacks to WebSocketApp.
  • Reconnects through its built-in dispatcher. Set a reconnect delay on run_forever for automatic retries.

Limitations

  • Compression needs a different client. Choose another client when the peer requires permessage-deflate.
  • Asyncio needs another integration. Choose a native asyncio client for coroutine-based applications.

Quickstart

From README.md
$ python3 -m pip install websocket-client
from websocket import create_connection
ws = create_connection("ws://echo.websocket.events/")
print(ws.recv())
print("Sending 'Hello, World'...")
ws.send("Hello, World")
print("Sent")
print("Receiving...")
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

websocket-client examples

From open-source projects on GitHub

Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed.

Downloads / mo
122.3M
Stars
22.2K
Last release
6.6.1
License
Apache-2.0

Quickstart

From websocket.html
$ python3 -m pip install tornado
import asyncio
from tornado.websocket import websocket_connect
async def main():
    connection = await websocket_connect('ws://localhost:8765')
    await connection.write_message('hello')
    connection.close()
asyncio.run(main())

Tornado examples

From open-source projects on GitHub

Implements WebSocket protocol state and frame handling without owning network I/O.

Downloads / mo
74.9M
Stars
303
Last release
1.3.2
License
MIT

Strengths

  • Fits custom network transports. Embed the protocol state machine in the application’s own transport.
  • Supports client and server roles. Use the same protocol class for either end of a WebSocket connection.

Limitations

  • Network I/O stays application-owned. Provide the code that reads and writes bytes on the actual connection.

Quickstart

From synchronous_client.py
$ python3 -m pip install wsproto
from wsproto import WSConnection, ConnectionType
from wsproto.events import Request

wsproto examples

From open-source projects on GitHub

simple-websocket

Provides a WebSocket server and client for Python.

Downloads / mo
28.7M
Stars
90
Last release
1.1.0
License
MIT

Quickstart

From intro.html
$ python3 -m pip install simple-websocket
from simple_websocket import Client
ws = Client.connect('ws://localhost:5000/echo')
ws.send('hello')
ws.close()

simple-websocket examples

From open-source projects on GitHub

Provides WebSocket support for Trio.

Downloads / mo
27.8M
Stars
81
Last release
0.12.2
License
MIT

Quickstart

From README.md
$ python3 -m pip install trio-websocket
import trio
from sys import stderr
from trio_websocket import open_websocket_url
async def main():
    try:
        async with open_websocket_url('wss://echo.websocket.org') as ws:
            await ws.send_message('hello world!')
            message = await ws.get_message()
            print('Received message: %s' % message)
    except OSError as ose:
        print('Connection attempt failed: %s' % ose, file=stderr)
trio.run(main)

Trio WebSocket examples

From open-source projects on GitHub

FAQ

websockets suits servers and clients that use asyncio or threads. websocket-client suits callback-based client connections outside asyncio. wsproto suits custom transports that own their network I/O.

websockets builds WebSocket servers and clients with coroutine-based or threaded APIs. Only one coroutine at a time should receive messages from each connection.

Its asynchronous connect iterator retries transient connection failures with exponential backoff.

websocket-client provides low-level WebSocket client APIs and callback-based long-lived connections. Applications built on asyncio need a native asyncio client instead.

For coding agents

Found your WebSocket library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official