{"name":"websockets: A Python Library for WebSocket Servers and Clients","description":"websockets is a robust Python library designed for building WebSocket servers and clients with a focus on correctness, simplicity, robustness, and performance. It leverages Python's `asyncio` framework for an elegant coroutine-based API, also offering `threading` and Sans-I/O implementations. This library provides a reliable foundation for real-time communication in Python applications.","github":"https://github.com/aaugustin/websockets","url":"https://osrepos.com/repo/aaugustin-websockets","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/aaugustin-websockets","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/aaugustin-websockets.md","json":"https://osrepos.com/repo/aaugustin-websockets.json","topics":["python","websocket","asyncio","networking","server","client","library"],"keywords":["python","websocket","asyncio","networking","server","client","library"],"stars":null,"summary":"websockets is a robust Python library designed for building WebSocket servers and clients with a focus on correctness, simplicity, robustness, and performance. It leverages Python's `asyncio` framework for an elegant coroutine-based API, also offering `threading` and Sans-I/O implementations. This library provides a reliable foundation for real-time communication in Python applications.","content":"## Introduction\n\nwebsockets is a robust Python library designed for building WebSocket servers and clients. It emphasizes correctness, simplicity, robustness, and performance, providing an elegant coroutine-based API built on Python's standard asynchronous I/O framework, `asyncio`. It also offers `threading` and Sans-I/O implementations for different use cases.\n\n## Installation\n\nTo get started with `websockets`, you can install it using pip:\n\nbash\npip install websockets\n\n\n## Examples\n\nHere's an echo server using the `asyncio` API:\n\npython\n#!/usr/bin/env python\n\nimport asyncio\nfrom websockets.asyncio.server import serve\n\nasync def echo(websocket):\n    async for message in websocket:\n        await websocket.send(message)\n\nasync def main():\n    async with serve(echo, \"localhost\", 8765) as server:\n        await server.serve_forever()\n\nasyncio.run(main())\n\n\nAnd here's how a client sends and receives messages with the `threading` API:\n\npython\n#!/usr/bin/env python\n\nfrom websockets.sync.client import connect\n\ndef hello():\n    with connect(\"ws://localhost:8765\") as websocket:\n        websocket.send(\"Hello world!\")\n        message = websocket.recv()\n        print(f\"Received: {message}\")\n\nhello()\n\n\n## Why use websockets?\n\nThe `websockets` library is developed with four core principles in mind:\n\n*   **Correctness**: `websockets` is heavily tested for compliance with RFC 6455. Continuous integration ensures 100% branch coverage.\n*   **Simplicity**: It offers a straightforward API, allowing developers to focus on application logic while it manages connections.\n*   **Robustness**: Built for production environments, `websockets` is known for correctly handling backpressure, a critical aspect in asynchronous programming.\n*   **Performance**: Memory usage is optimized and configurable. A C extension accelerates expensive operations, pre-compiled for Linux, macOS, and Windows, and packaged in the wheel format for each system and Python version.\n\n## Links\n\nFind more information and contribute to the `websockets` project:\n\n*   [GitHub Repository](https://github.com/python-websockets/websockets)\n*   [Official Documentation](https://websockets.readthedocs.io/)\n*   [PyPI Package](https://pypi.org/project/websockets/)","metrics":{"detailViews":3,"githubClicks":10},"dates":{"published":null,"modified":"2026-04-18T00:11:15.000Z"}}