pamoja-bus
An in-memory typed publish and subscribe event bus, with publishers that never wait and subscribers that count what they miss. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.
Install
pip install pamoja-bus
from pamoja import bus
This pulls in pamoja-native, the compiled engine. pip install pamoja is the whole framework in one package.
Example
The script the test suite runs, spliced here as it ran.
From bindings/python/guides/bus.py:
import asyncio
from pamoja.bus import EventPublisher
QUIET_MS = 50
async def main() -> None:
# The station's wiring makes one bus and hands each part what it needs: a publisher
# to announce, an endpoint to listen. No part holds a reference to another, so any
# of them can be replaced without touching the rest.
bus = EventPublisher(2)
power = bus.publisher()
sampler = bus.publisher()
heater = bus.subscribe()
logger = bus.subscribe()
# One announcement reaches every part that listens, and each reads its own copy.
reached = power.publish("battery.low")
print(f"power handed battery.low to {reached} parts")
heater_took = await heater.next_text()
print(f"heater took {heater_took}")
logger_took = await logger.next_text()
print(f"logger took {logger_took}")
# Publishing never waits, even while the part's own wait is open, and a part hears
# what it publishes.
waiting = heater.next_text()
heater.publish("heater.off")
heard = await waiting
print(f"heater heard its own {heard}, sent while it waited")
# A part that joins late sees only what is published after it subscribes. There is
# no history to replay.
radio = bus.subscribe()
power.publish("battery.ok")
first = await radio.next_text()
print(f"radio joined late, so the first event it sees is {first}")
# Each endpoint buffers two events. The logger, busy writing to flash, falls behind
# while the sampler publishes five readings: it loses the oldest events, resumes
# with the newest, and counts what it lost.
for reading in range(5):
sampler.publish(f"wind {reading}")
resumed = await logger.next_text()
missed = logger.missed
print(f"logger missed {missed} and resumes at {resumed}")
newest = await logger.next_text()
print(f"logger then took {newest}")
# A wait with a limit gives up without taking anything, so a part can do other work
# between events and lose nothing by it.
try:
await asyncio.wait_for(logger.next_text(), QUIET_MS / 1000)
print("logger took an event no one published, which should never happen")
except asyncio.TimeoutError:
print(f"logger heard nothing more within {QUIET_MS} ms")
return reached, heater_took, logger_took, heard, first, missed, resumed, newest
seen = asyncio.run(main())
The same capability in every language
| Language | Package | Reference |
|---|---|---|
| Rust | pamoja-bus |
reference, docs.rs, install |
| TypeScript | @pamoja/bus |
reference, install |
| Python | pamoja-bus |
reference, install |
| C# | Pamoja.Bus |
reference, install |
Documentation
pamoja.busreference, every class and function in this module.- The Event bus guide, with the same example in Rust, TypeScript, and C#.
- Every capability, and the install page.
License
MIT
Metadata
Release files for pamoja-bus 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pamoja_bus-0.2.1.tar.gz | 3.7 kB | Without provenance | Details for pamoja_bus-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pamoja_bus-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for pamoja_bus-0.2.1-py3-none-any.whl |
Total release size: 7.9 kB
Release files / pamoja_bus-0.2.1.tar.gz
| Download URL | pamoja_bus-0.2.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0b202b1d0d4bab8f8be84fb60fd64d75e26e44476eae0058812d1c08cd2e5502
|
|
BLAKE2b-256 checksum How to use checksums |
7349cf3be1ba8192d40cb01a92c94e8f2386f618203d3d8ce269b060de2df6f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Release files / pamoja_bus-0.2.1-py3-none-any.whl
| Download URL | pamoja_bus-0.2.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e4724996a1af47129325e22f79e91d3d481f753a47567e054c5e7c3b1bc225d1
|
|
BLAKE2b-256 checksum How to use checksums |
031c73fa0cd887917a30c41cca65a39d004a6054834893a41ae0d4db28d84c65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.18
|
Security for pamoja-bus 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.