Skip to main content

zmqtt

Pure asyncio MQTT 3.1.1 and 5.0 client library. No paho dependency, no threading, no god classes. See documentation.

Why not aiomqtt?

aiomqtt is a thin async wrapper around paho-mqtt. You inherit paho's threading model, 10 000-line files, and implicit global state — just with async/await painted on top.

zmqtt is built from scratch:

zmqtt aiomqtt (paho)
I/O model pure asyncio paho threads + asyncio bridge
Packet codec pure functions, I/O-free paho internals
MQTT 5.0 native, typed properties dataclasses partial
Type annotations strict mypy partial
Backpressure bounded subscription queues none

Installation

pip install zmqtt

Quick start

import asyncio
from zmqtt import MQTTClient

async def main():
    async with MQTTClient("broker.example.com") as client:
        async with client.subscribe("sensors/#") as messages:
            async for msg in messages:
                print(msg.topic, msg.payload)

asyncio.run(main())

Or manage connections and subscriptions manually:

import asyncio
from zmqtt import MQTTClient

async def main():
    client = MQTTClient("broker.example.com")
    await client.connect()

    subscription = client.subscribe("sensors/#")
    await subscription.start()

    msg = await subscription.get_message()
    print(msg.topic, msg.payload)

    await subscription.stop()
    await client.disconnect()

asyncio.run(main())

Publish

async with MQTTClient("broker.example.com") as client:
    await client.publish("sensors/temperature", b"23.5", qos=1)

QoS levels

from zmqtt import QoS

await client.publish("topic", b"data", qos=QoS.AT_LEAST_ONCE)   # QoS 1
await client.publish("topic", b"data", qos=QoS.EXACTLY_ONCE)    # QoS 2

Manual acknowledgement

Hold the PUBACK/PUBREC until your application has durably processed the message:

async with client.subscribe("orders/#", auto_ack=False) as messages:
    async for msg in messages:
        await save_to_database(msg)
        await msg.ack()  # broker will redeliver if we crash before this

Subscription as explicit get

Useful when interleaving message handling with other async work:

async with client.subscribe("sensors/#") as messages:
    msg = await messages.get_message()
    print(msg.topic, msg.payload)

Reconnection

MQTTClient reconnects automatically with exponential backoff. Active subscriptions are transparently re-registered after reconnect — your async for loop keeps running.

MQTT 5.0

Pass version="5.0" to use MQTT 5.0. Properties are typed dataclasses:

from zmqtt import MQTTClient, PublishProperties

async with MQTTClient("broker.example.com", version="5.0") as client:
    props = PublishProperties(content_type="application/json")
    await client.publish("topic", b'{"value": 42}', properties=props)

Download files

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

Source Distribution

zmqtt-0.1.0.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

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

zmqtt-0.1.0-py3-none-any.whl (46.1 kB view details)

Uploaded Python 3

File details

Details for the file zmqtt-0.1.0.tar.gz.

File metadata

  • Download URL: zmqtt-0.1.0.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for zmqtt-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2f8aa02f10ecf17e6447a5c93ae9f91a36cf2a0d436cf8dd9adb6f478e590d89
MD5 dd1b2ca20fbe2f6edfbab2dc3c83e7f4
BLAKE2b-256 36b31e399acf9e939e663a8c6149a7d4eb875e376d63c2ac8c3cd361f197d3af

See more details on using hashes here.

Provenance

The following attestation bundles were made for zmqtt-0.1.0.tar.gz:

Publisher: release.yaml on faststream-community/zMQTT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file zmqtt-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: zmqtt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 46.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for zmqtt-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cc6d3e081284836371acda86ff2d8413d0230317a28f665a0f08ff8544f3d1d
MD5 5a2cdd27fa7c5558beec51931156150f
BLAKE2b-256 b8fba574b2aedf21d4bebc688554c9f93bd66aca01933c4117f9e533cae99f1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for zmqtt-0.1.0-py3-none-any.whl:

Publisher: release.yaml on faststream-community/zMQTT

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page