{"id":13616348,"url":"https://github.com/encode/broadcaster","last_synced_at":"2025-04-10T10:44:49.979Z","repository":{"id":37990675,"uuid":"241368543","full_name":"encode/broadcaster","owner":"encode","description":"Broadcast channels for async web apps. 📢","archived":false,"fork":false,"pushed_at":"2025-03-16T13:14:47.000Z","size":440,"stargazers_count":1176,"open_issues_count":11,"forks_count":125,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-04-03T05:32:03.290Z","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":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/encode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","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},"funding":{"github":"encode"}},"created_at":"2020-02-18T13:32:03.000Z","updated_at":"2025-04-01T19:06:57.000Z","dependencies_parsed_at":"2024-04-22T17:03:53.210Z","dependency_job_id":"c30be09e-57de-4f31-9d54-6d7d1ffb9b24","html_url":"https://github.com/encode/broadcaster","commit_stats":{"total_commits":36,"total_committers":9,"mean_commits":4.0,"dds":0.5555555555555556,"last_synced_commit":"ccd476e1c03aa54541f966183f839278c34b0d3d"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fbroadcaster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fbroadcaster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fbroadcaster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/encode%2Fbroadcaster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/encode","download_url":"https://codeload.github.com/encode/broadcaster/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055268,"owners_count":21040157,"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":"2024-08-01T20:01:27.281Z","updated_at":"2025-04-10T10:44:49.959Z","avatar_url":"https://github.com/encode.png","language":"Python","readme":"# Broadcaster\n\nBroadcaster helps you develop realtime streaming functionality by providing\na simple broadcast API onto a number of different backend services.\n\nIt currently supports [Redis PUB/SUB](https://redis.io/topics/pubsub), [Redis Streams](https://redis.io/docs/latest/develop/data-types/streams/), [Apache Kafka](https://kafka.apache.org/), and [Postgres LISTEN/NOTIFY](https://www.postgresql.org/docs/current/sql-notify.html), plus a simple in-memory backend, that you can use for local development or during testing.\n\n\u003cimg src=\"https://raw.githubusercontent.com/encode/broadcaster/master/docs/demo.gif\" alt='WebSockets Demo'\u003e\n\nHere's a complete example of the backend code for a simple websocket chat app:\n\n**app.py**\n\n```python\n# Requires: `starlette`, `uvicorn`, `jinja2`\n# Run with `uvicorn example:app`\nimport anyio\nfrom broadcaster import Broadcast\nfrom starlette.applications import Starlette\nfrom starlette.routing import Route, WebSocketRoute\nfrom starlette.templating import Jinja2Templates\n\n\nbroadcast = Broadcast(\"redis://localhost:6379\")\ntemplates = Jinja2Templates(\"templates\")\n\n\nasync def homepage(request):\n    template = \"index.html\"\n    context = {\"request\": request}\n    return templates.TemplateResponse(template, context)\n\n\nasync def chatroom_ws(websocket):\n    await websocket.accept()\n\n    async with anyio.create_task_group() as task_group:\n        # run until first is complete\n        async def run_chatroom_ws_receiver() -\u003e None:\n            await chatroom_ws_receiver(websocket=websocket)\n            task_group.cancel_scope.cancel()\n\n        task_group.start_soon(run_chatroom_ws_receiver)\n        await chatroom_ws_sender(websocket)\n\n\nasync def chatroom_ws_receiver(websocket):\n    async for message in websocket.iter_text():\n        await broadcast.publish(channel=\"chatroom\", message=message)\n\n\nasync def chatroom_ws_sender(websocket):\n    async with broadcast.subscribe(channel=\"chatroom\") as subscriber:\n        async for event in subscriber:\n            await websocket.send_text(event.message)\n\n\nroutes = [\n    Route(\"/\", homepage),\n    WebSocketRoute(\"/\", chatroom_ws, name='chatroom_ws'),\n]\n\n\napp = Starlette(\n    routes=routes, on_startup=[broadcast.connect], on_shutdown=[broadcast.disconnect],\n)\n```\n\nThe HTML template for the front end [is available here](https://github.com/encode/broadcaster/blob/master/example/templates/index.html), and is adapted from [Pieter Noordhuis's PUB/SUB demo](https://gist.github.com/pietern/348262).\n\n## Requirements\n\nPython 3.8+\n\n## Installation\n\n* `pip install broadcaster`\n* `pip install broadcaster[redis]`\n* `pip install broadcaster[postgres]`\n* `pip install broadcaster[kafka]`\n\n## Available backends\n\n* `Broadcast('memory://')`\n* `Broadcast(\"redis://localhost:6379\")`\n* `Broadcast(\"redis-stream://localhost:6379\")`\n* `Broadcast(\"postgres://localhost:5432/broadcaster\")`\n* `Broadcast(\"kafka://localhost:9092\")`\n\n\n### Using custom backends\n\nYou can create your own backend and use it with `broadcaster`.\nTo do that you need to create a class which extends from `BroadcastBackend`\nand pass it to the `broadcaster` via `backend` argument.\n\n```python\nfrom broadcaster import Broadcaster, BroadcastBackend\n\nclass MyBackend(BroadcastBackend):\n\nbroadcaster = Broadcaster(backend=MyBackend())\n```\n\n## Where next?\n\nAt the moment `broadcaster` is in Alpha, and should be considered a working design document.\n\nThe API should be considered subject to change. If you *do* want to use Broadcaster in its current\nstate, make sure to strictly pin your requirements to `broadcaster==0.3.0`.\n\nTo be more capable we'd really want to add some additional backends, provide API support for reading recent event history from persistent stores, and provide a serialization/deserialization API...\n\n* Serialization / deserialization to support broadcasting structured data.\n* A backend for RabbitMQ.\n* Add support for `subscribe('chatroom', history=100)` for backends which provide persistence. (Redis Streams, Apache Kafka) This will allow applications to subscribe to channel updates, while also being given an initial window onto the most recent events. We *might* also want to support some basic paging operations, to allow applications to scan back in the event history.\n* Support for pattern subscribes in backends that support it.\n\n## Third Party Packages\n\n### MQTT backend\n[Gist](https://gist.github.com/alex-oleshkevich/68411a0e7ad24d53afd28c3fa5da468c)\n\nIntegrates MQTT with Broadcaster\n","funding_links":["https://github.com/sponsors/encode"],"categories":["HarmonyOS","Python"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fencode%2Fbroadcaster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fencode%2Fbroadcaster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fencode%2Fbroadcaster/lists"}