Skip to main content

pamoja-loopback

An in-process transport with topic matching, a fault injector, and outages on demand, for testing with no broker. One capability of pamoja, one memory-safe Rust core with bindings for TypeScript, Python, and C#.

read the guide documentation API reference

Install

pip install pamoja-loopback
from pamoja import loopback

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/loopback.py:

import asyncio

from pamoja.core import PamojaError
from pamoja.loopback import LoopbackBroker

QUIET_MS = 50


async def main() -> None:
    # One broker and two links off it, all in this process. Nothing binds a port and
    # nothing has to be running for the traffic below to flow, which is what makes this
    # the link to develop a node against before it has a real one.
    broker = LoopbackBroker()
    publisher = broker.link()
    subscriber = broker.link()
    await publisher.connect()
    await subscriber.connect()

    # A `+` stands for exactly one level, so this takes the mixer's temperature but not the
    # raw reading a level below it.
    await subscriber.subscribe("line/+/temp")
    await publisher.send("line/mixer/temp/raw", "2150")
    await publisher.send("line/mixer/temp", "21.5")

    message = await subscriber.recv()
    print(f"line/+/temp took {message.text} from {message.topic}")

    # The raw reading went out first and never arrived, which a test proves by waiting a
    # set time for anything more rather than forever. Giving up loses nothing: a message
    # that came later would wait for the next receive.
    try:
        await asyncio.wait_for(subscriber.recv(), QUIET_MS / 1000)
        print("line/+/temp took a second reading, which should never happen")
    except asyncio.TimeoutError:
        print(f"line/+/temp heard nothing more within {QUIET_MS} ms")

    # A `#` covers every level that remains, so a second link takes the whole subtree,
    # including the reading the single-level filter passed over.
    watcher = broker.link()
    await watcher.connect()
    await watcher.subscribe("line/#")
    await publisher.send("line/mixer/temp/raw", "2150")

    deep = await watcher.recv()
    print(f"line/#     took {deep.text} from {deep.topic}")

    # A link that has been disconnected reports the failure instead of dropping the
    # reading, which is the case a test wants to reach without unplugging anything.
    await publisher.disconnect()
    try:
        await publisher.send("line/mixer/temp", "21.6")
        print("a disconnected link took a reading, which should never happen")
    except PamojaError as error:
        print(f"disconnected refused the reading: {error}")

    return message, deep


message, deep = asyncio.run(main())

The same capability in every language

Language Package Reference
Rust pamoja-loopback reference, docs.rs, install
TypeScript @pamoja/loopback reference, install
Python pamoja-loopback reference, install
C# Pamoja.Loopback reference, install

Documentation

License

MIT

Metadata

Release files for pamoja-loopback 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pamoja-loopback 0.2.1
File Size Uploaded Provenance Actions
pamoja_loopback-0.2.1.tar.gz 3.5 kB Without provenance Details for pamoja_loopback-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-loopback 0.2.1
File Interpreter ABI Platform Actions
pamoja_loopback-0.2.1-py3-none-any.whl Python 3 none any Details for pamoja_loopback-0.2.1-py3-none-any.whl

Total release size: 7.7 kB

Release files / pamoja_loopback-0.2.1.tar.gz

Download URL pamoja_loopback-0.2.1.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
620590c25a1eb90346bed33fd997f09fa4ba7b4d627154d7971f88c4b9d9c924
BLAKE2b-256 checksum
How to use checksums
7361ca9ca120b0320cd9331c663da7e5bb833a71e3662588a7c7487b92bd9786
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / pamoja_loopback-0.2.1-py3-none-any.whl

Download URL pamoja_loopback-0.2.1-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa1fb1aaea3ebfd69748a5408c64350f22b27887bc56477bad1981a321751898
BLAKE2b-256 checksum
How to use checksums
49cd74da3e85432e9bc9653b74c2616293d98561cadfc55df3abe5f1f1b01491
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Security for pamoja-loopback 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.

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