Registry / web-framework / broadcaster

broadcaster

JSON →
library0.3.1pypypi✓ verified 83d ago

Broadcaster provides a simple, asynchronous publish/subscribe interface for Python 3.8+, allowing for broadcast channels across various backends like Redis, PostgreSQL, and Kafka. The current version is 0.3.1. It's actively maintained by the Encode organization, known for projects like Starlette and Uvicorn, suggesting a steady, incremental release cadence.

pip install broadcaster
INSTALL
IMPORT
SIG · BROADCASTER
B
broadcaster
web-frameworkpythonv0.3.1
Install
2.3s avg
Import
Disk
40MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
2/4 runs
✓ 2.3s
py 3.11
2/4 runs
✓ 2.3s
py 3.12
2/4 runs
✓ 2.1s
py 3.13
2/4 runs
✓ 2.15s
py 3.9
2/4 runs
✓ 2.55s
40MB installed
● package 40MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Broadcast
from broadcaster import Broadcast
from broadcaster import Broadcaster
BroadcastBackend
from broadcaster import BroadcastBackend
Event
from broadcaster import Event

This quickstart demonstrates setting up an in-memory (default) or environment-variable-configured Broadcaster. It connects, publishes a message to a channel, and then subscribes and retrieves that message. Remember to set the `BROADCAST_URL` environment variable (e.g., `redis://localhost:6379`) to use a different backend, and ensure the corresponding optional dependency is installed.

import asyncio import os from broadcaster import Broadcaster BROADCAST_URL = os.environ.get("BROADCAST_URL", "memory://") async def main(): # Initialize broadcaster with a URL, defaults to in-memory if env var is not set broadcaster = Broadcaster(BROADCAST_URL) # Establish connection to the backend await broadcaster.connect() async with broadcaster.subscribe("chat") as subscriber: # Publish a message await broadcaster.publish("chat", "Hello from broadcaster!") print(f"Published: Hello from broadcaster!") # Receive a message message = await subscriber.get() print(f"Received: {message}") # Disconnect from the backend await broadcaster.disconnect() if __name__ == "__main__": asyncio.run(main())
Debug
Known issues
gotchaBackend dependencies (e.g., Redis, PostgreSQL, Kafka) are optional and must be explicitly installed for each chosen backend. Installing just `broadcaster` will only provide the in-memory backend.
fix
Install the specific backend dependency using extras, e.g., `pip install "broadcaster[redis]"` for Redis, or `pip install "broadcaster[postgres]"` for PostgreSQL.
affects: >=0.1.0
gotchaAlways ensure to `await broadcaster.connect()` before publishing or subscribing, and `await broadcaster.disconnect()` afterwards. Forgetting these can lead to resource leaks or operations failing due to a lack of an active connection.
fix
Add `await broadcaster.connect()` at the start of your Broadcaster operations and `await broadcaster.disconnect()` when done, or use context managers for subscriptions where applicable.
affects: >=0.1.0
gotchaBroadcaster is an asyncio-first library. All interaction methods like `publish()` and `subscribe()` are coroutines and must be `await`ed. Mixing synchronous and asynchronous code without proper handling will lead to `TypeError: object 'coroutine' can't be used in 'await' expression` or other runtime errors.
fix
Ensure all Broadcaster operations are awaited within an `async` function and the application's event loop is properly managed (e.g., using `asyncio.run()` for top-level execution).
affects: >=0.1.0
Upgrade
Version history
0.3.1latest on PyPI · released Aug 1, 2024
Audit
Dependencies
redisoptionalRequired for Redis backend support via 'broadcaster[redis]'.
asyncpgoptionalRequired for PostgreSQL backend support via 'broadcaster[postgres]'.
aiokafkaoptionalRequired for Kafka backend support via 'broadcaster[kafka]'.
Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
broadcaster — pip install broadcaster · libregistry