Skip to main content

pamoja-bus

An in-memory typed publish and subscribe event bus. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.

API reference read the guide documentation

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 EventBus


async def main() -> None:
    # A sampler announces something and whatever cares picks it up, with neither side
    # holding a reference to the other. This is how the parts of one node are wired.
    hub = EventBus(8)
    control = await hub.subscribe()
    logger = await hub.subscribe()

    await hub.publish(b"battery.low")
    to_control = await control.next_event()
    to_logger = await logger.next_event()
    print(f"control saw {to_control.decode()}, the logger saw {to_logger.decode()}")

    # A subscriber taken later starts from the next event, so it never sees what went out
    # before it existed.
    late = await hub.subscribe()
    await hub.publish(b"link.up")
    first_seen = await late.next_event()
    print(f"the late subscriber's first event is {first_seen.decode()}")

    # The buffer is per subscriber and bounded, so one further behind than the capacity
    # drops what it missed and resumes with the most recent events. A slow reader costs
    # itself, not the publisher.
    slow = EventBus(2)
    reader = await slow.subscribe()
    for count in range(5):
        await slow.publish(bytes([count]))
    resumed = await reader.next_event()
    print(f"after five events into a buffer of two, the reader resumes at {resumed[0]}")

    return to_control, to_logger, first_seen, resumed


to_control, to_logger, first_seen, resumed = asyncio.run(main())

The same capability in every language

Language Package Reference
Rust pamoja-bus reference, docs.rs
TypeScript @pamoja/bus reference
Python pamoja-bus reference
C# Pamoja.Bus reference

Documentation

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pamoja_bus-0.1.15.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pamoja_bus-0.1.15-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file pamoja_bus-0.1.15.tar.gz.

File metadata

  • Download URL: pamoja_bus-0.1.15.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.15.0

File hashes

Hashes for pamoja_bus-0.1.15.tar.gz
Algorithm Hash digest
SHA256 d2f797ec782a18a4744d063f5b67a530328ffcd894c2996a724386dc33fa43ed
MD5 0bff18ad3b0785d4caa0f5bc77afc78e
BLAKE2b-256 5ce94cf472d11806acb7d3ffae027de56d53e288c5b5fcdc623edad805c40fdb

See more details on using hashes here.

File details

Details for the file pamoja_bus-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: pamoja_bus-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.15.0

File hashes

Hashes for pamoja_bus-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 e5b5eb8a7dff96766e8a2bdd49d7e1d07c380555f142128554072249bd80eccf
MD5 4ea8cdac3b083e092b332df99151bfad
BLAKE2b-256 36559289d37866825a170b54e52b0462b7695fa485fbf3c0195d790754389457

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.17

2 files

0.1.16

2 files

This release

0.1.15 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page