{"id":28537542,"url":"https://github.com/python-trio/trio-websocket","last_synced_at":"2025-12-11T21:03:18.265Z","repository":{"id":45079920,"uuid":"146345539","full_name":"python-trio/trio-websocket","owner":"python-trio","description":"WebSocket client and server implementation for Python Trio","archived":false,"fork":false,"pushed_at":"2025-02-25T05:23:17.000Z","size":339,"stargazers_count":75,"open_issues_count":18,"forks_count":30,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-07-01T22:05:34.285Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/python-trio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/contributing.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"python-trio","open_collective":"python-trio"}},"created_at":"2018-08-27T19:42:15.000Z","updated_at":"2025-02-25T05:23:21.000Z","dependencies_parsed_at":"2023-11-06T20:59:30.959Z","dependency_job_id":"c0ad8b96-6828-481d-a939-2eb6fddbe484","html_url":"https://github.com/python-trio/trio-websocket","commit_stats":{"total_commits":219,"total_committers":12,"mean_commits":18.25,"dds":0.5205479452054795,"last_synced_commit":"6a004bbf4749791e89f15f57cb2aced2c442246f"},"previous_names":["python-trio/trio-websocket","hyperiongray/trio-websocket"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/python-trio/trio-websocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/python-trio","download_url":"https://codeload.github.com/python-trio/trio-websocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/python-trio%2Ftrio-websocket/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264221667,"owners_count":23575071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-09T18:10:12.104Z","updated_at":"2025-12-11T21:03:13.196Z","avatar_url":"https://github.com/python-trio.png","language":"Python","funding_links":["https://github.com/sponsors/python-trio","https://opencollective.com/python-trio"],"categories":[],"sub_categories":[],"readme":"# Trio WebSocket\n\nThis library implements both server and client aspects of the [the WebSocket\nprotocol](https://tools.ietf.org/html/rfc6455), striving for safety,\ncorrectness, and ergonomics. It is based on the [wsproto\nproject](https://wsproto.readthedocs.io/en/latest/), which is a\n[Sans-IO](https://sans-io.readthedocs.io/) state machine that implements the\nmajority of the WebSocket protocol, including framing, codecs, and events. This\nlibrary handles I/O using [the Trio\nframework](https://trio.readthedocs.io/en/latest/). This library passes the\n[Autobahn Test Suite](https://github.com/crossbario/autobahn-testsuite).\n\nThis README contains a brief introduction to the project. Full documentation [is\navailable here](https://trio-websocket.readthedocs.io).\n\n[![PyPI](https://img.shields.io/pypi/v/trio-websocket.svg?style=flat-square)](https://pypi.org/project/trio-websocket/)\n![Python Versions](https://img.shields.io/pypi/pyversions/trio-websocket.svg?style=flat-square)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/python-trio/trio-websocket/ci.yml)](https://github.com/python-trio/trio-websocket/actions/workflows/ci.yml)\n[![Read the Docs](https://img.shields.io/readthedocs/trio-websocket.svg)](https://trio-websocket.readthedocs.io)\n[![Join chatroom](https://img.shields.io/badge/chat-join%20now-blue.svg)](https://gitter.im/python-trio/general)\n\n## Status\n**This project is on life-support maintenance.** If you're interested in helping to maintain and contribute, please reach out on [Gitter](https://gitter.im/python-trio/general) or contribute in issues and pull requests.\n\n## Alternatives\n\nIf you happen to only need a server, using Quart via the [quart-trio](https://github.com/pgjones/quart-trio)\nextension may suffice.  While trio-websocket is more flexible, Quart covers\nboth HTTP and WebSocket within a single framework, and serving both from the\nsame port is straightforward.  There has yet to be a performance comparison.\n\n## Installation\n\nThis library requires Python 3.8 or greater. To install from PyPI:\n\n    pip install trio-websocket\n\n## Client Example\n\nThis example demonstrates how to open a WebSocket URL:\n\n```python\nimport trio\nfrom sys import stderr\nfrom trio_websocket import open_websocket_url\n\n\nasync def main():\n    try:\n        async with open_websocket_url('wss://echo.websocket.org') as ws:\n            await ws.send_message('hello world!')\n            message = await ws.get_message()\n            print('Received message: %s' % message)\n    except OSError as ose:\n        print('Connection attempt failed: %s' % ose, file=stderr)\n\ntrio.run(main)\n```\n\nThe WebSocket context manager connects automatically before entering the block\nand disconnects automatically before exiting the block. The full API offers a\nlot of flexibility and additional options.\n\n## Server Example\n\nA WebSocket server requires a bind address, a port, and a coroutine to handle\nincoming connections. This example demonstrates an \"echo server\" that replies to\neach incoming message with an identical outgoing message.\n\n```python\nimport trio\nfrom trio_websocket import serve_websocket, ConnectionClosed\n\nasync def echo_server(request):\n    ws = await request.accept()\n    while True:\n        try:\n            message = await ws.get_message()\n            await ws.send_message(message)\n        except ConnectionClosed:\n            break\n\nasync def main():\n    await serve_websocket(echo_server, '127.0.0.1', 8000, ssl_context=None)\n\ntrio.run(main)\n```\n\nThe server's handler ``echo_server(…)`` receives a connection request object.\nThis object can be used to inspect the client's request and modify the\nhandshake, then it can be exchanged for an actual WebSocket object ``ws``.\nAgain, the full API offers a lot of flexibility and additional options.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Ftrio-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpython-trio%2Ftrio-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpython-trio%2Ftrio-websocket/lists"}