Skip to main content

pamoja-mqtt

An MQTT client with the topic and wildcard rules, as the core transport. 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-mqtt
from pamoja import mqtt

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

import asyncio

from pamoja.core import PamojaError
from pamoja.mqtt import MqttClient, Qos

# The broker on the site. The guide's CI runs one on localhost; point these at yours and
# nothing else changes.
BROKER = "127.0.0.1"
PORT = 1883


async def main() -> None:
    # The gateway takes every temperature on the site. A `+` stands for exactly one level,
    # so this matches every node's temperature and nothing deeper.
    gateway = MqttClient(
        client_id="site-gateway", host=BROKER, port=PORT, qos=Qos.AT_LEAST_ONCE
    )
    await gateway.connect()
    await gateway.subscribe("sensors/+/temperature")
    print("gateway   subscribed to sensors/+/temperature")

    # A node publishes under that pattern. At-least-once means the broker acknowledges the
    # message, so a node knows its reading was taken rather than hoping.
    node = MqttClient(client_id="node-1", host=BROKER, port=PORT, qos=Qos.AT_LEAST_ONCE)
    await node.connect()
    await node.publish("sensors/1/temperature", "21.5")
    print("node      published 21.5 to sensors/1/temperature")

    # The gateway receives it with the topic attached, which is how it knows which node
    # sent the reading without the payload having to repeat it.
    received = await gateway.recv()
    print(f"gateway   got {received.payload.decode()} on {received.topic}")

    # Disconnecting leaves the client reusable, so a node that loses its link can
    # reconnect the same object when the broker comes back.
    await node.disconnect()
    print(f"node      disconnected, still connected: {await node.is_connected()}")
    await gateway.disconnect()

    # A broker that is not there is reported rather than leaving a client that looks
    # connected, so a retry loop has something to test.
    nowhere = MqttClient(client_id="node-2", host=BROKER, port=1, keep_alive_secs=1)
    try:
        await nowhere.connect()
        print("an unreachable broker accepted a connection, which should never happen")
    except PamojaError as error:
        print(f"unreachable broker refused: {error}")

    return received


received = asyncio.run(main())

The same capability in every language

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

Documentation

License

MIT

Release files for pamoja-mqtt 0.1.17

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-mqtt 0.1.17
File Size Uploaded
pamoja_mqtt-0.1.17.tar.gz 4.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pamoja-mqtt 0.1.17
File Interpreter ABI Platform
pamoja_mqtt-0.1.17-py3-none-any.whl Python 3 none any Details

Total release size: 10.5 kB

Release files / pamoja_mqtt-0.1.17.tar.gz

Download URL pamoja_mqtt-0.1.17.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
48c63e44906bf8754da0dd721d28f66d601cec7f55a5f57b6f43aa4f3d4b86ca
BLAKE2b-256 checksum
How to use checksums
5895c1f492bf5d02c28779163d01d5deea48117ef7fae516dd4d78398890578b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / pamoja_mqtt-0.1.17-py3-none-any.whl

Download URL pamoja_mqtt-0.1.17-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5db21bb66d6f6d77b84f2a873fb944f665c8321ba1748e92a093e1d6a7c44ea1
BLAKE2b-256 checksum
How to use checksums
69642bc0f2165cad7cdb556b0824f22d227eaef6685598d41cf717a922625e90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.2.0

2 release files

0.1.18

2 release files

This release

0.1.17 This release

2 release 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