Pure asyncio MQTT 3.1.1/5.0 client library
Project description
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 to use MQTT 5.0. Properties are typed dataclasses:
from zmqtt import MQTTClient
from zmqtt._internal.packets.properties import PublishProperties
async with MQTTClient("broker.example.com", version=5) as client:
props = PublishProperties(content_type="application/json")
await client.publish("topic", b'{"value": 42}', properties=props)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file zmqtt-0.0.4.tar.gz.
File metadata
- Download URL: zmqtt-0.0.4.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10d7f97d3fac02ef82a44a46a004e2dba2115bdca39936536ceb5057a761418d
|
|
| MD5 |
40704e73626ce4ca4b5f9f11eccbdccd
|
|
| BLAKE2b-256 |
e86a3e7e94e099e1c85df9a166b02ec6fab0e4d3a9623dd9ca6bb6942d0f617a
|
File details
Details for the file zmqtt-0.0.4-py3-none-any.whl.
File metadata
- Download URL: zmqtt-0.0.4-py3-none-any.whl
- Upload date:
- Size: 37.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c509462855f15e6a2d02fe7f60abc1e2f4fe87a7996ae0a095e188b2b5afdbc
|
|
| MD5 |
b3af6e2ab4a227054d85017c5bae64ba
|
|
| BLAKE2b-256 |
e304ed0bcd6b7ad0a8e1fc27f1dd99caa72761bfa329fd993a12f44d3871eee7
|