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#.

read the guide documentation API reference

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.text} 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.18

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

Built distribution (wheel)

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

Total release size: 10.5 kB

Release files / pamoja_mqtt-0.1.18.tar.gz

Download URL pamoja_mqtt-0.1.18.tar.gz
Size 4.9 kB
Tags Source
SHA-256 checksum
How to use checksums
41dec5b81813b3b00c5f4628fd45d5e16050d92a0c7ceedf90798664569d604f
BLAKE2b-256 checksum
How to use checksums
596e8bd3d75281f55c56bcb5532426d848161d6a144fd44ef14bc7e2a8b31824
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.18-py3-none-any.whl

Download URL pamoja_mqtt-0.1.18-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a1e26cb422d6e06ace013129b5e838841c6a31ca3ca3e1a67766f3409a78d557
BLAKE2b-256 checksum
How to use checksums
6f2259bffb83fff3dc89613a3e85d43a25dd580b0d6c31f6397bd659a0050b74
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

This release

0.1.18 This release

2 release files

0.1.17

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