talira

websockets

Library for building WebSocket servers and clients in Python

open sourceBSD-3-Clausefree

websockets is a Python library for building WebSocket servers and clients, focused on correctness, simplicity, robustness and performance. Its default implementation is a coroutine API on asyncio, with implementations on threading and trio too and a Sans-I/O layer for other projects to build on. It is tested for compliance with RFC 6455 (WebSocket) and RFC 7692 (compression), with 100% branch coverage, handles backpressure, and has a C extension that speeds up expensive operations, shipped as pre-built wheels. HTTP and WebSocket servers such as Uvicorn build on it for their WebSocket support.

Problems it solves

  • run a WebSocket server in Python
  • connect to a WebSocket server from a Python script
  • add WebSockets to an asyncio app

Features

  • WebSocket servers and clients for Python
  • coroutine API on asyncio, plus threading and trio implementations
  • Sans-I/O layer for integration in other projects
  • compliance with RFC 6455 and RFC 7692 compression, with 100% branch coverage
  • handles backpressure
  • C extension, pre-built for Linux, macOS and Windows

Limitations

  • It has no callback-based API: pick another library if you prefer callbacks over coroutines.1
  • Its HTTP support is minimal, just enough for a health check; for HTTP and WebSocket in one server, use a server built on it such as Uvicorn.1