This release is a pre-release and may not be stable for production use.
MQTTium
A dependable, dependency-free asyncio MQTT client for Python.
MQTTium is an async-native MQTT 3.1.1 and MQTT 5 client for Python 3.11–3.14. It is designed for services, gateways, and connected devices that need explicit delivery semantics, bounded resource use, and predictable recovery when a connection or process fails.
The package has no runtime dependencies and is fully typed.
Why MQTTium?
| Need | MQTTium provides |
|---|---|
| Protocol coverage | MQTT 3.1.1 and MQTT 5, QoS 0/1/2, typed properties, Last Will, and enhanced authentication |
| Explicit completion | Publish receipts that separate local admission from the relevant MQTT acknowledgement exchange |
| Controlled load | Message and byte budgets, wait-or-refuse backpressure, bounded ingress, writes, and application delivery |
| Session continuity | Jittered reconnect plus in-memory or SQLite-backed inflight state with incremental replay |
| Delivery choices | Async iteration, sync or async callbacks, optional dual delivery, and manual acknowledgement |
| Transports | TCP, TLS, WebSocket, and Unix-domain sockets |
| Operations | Immutable runtime snapshots, queue high-water marks, and broker-negotiated limits |
| Efficient production | Bounded publish_many() and loop-bound publish_nowait() without changing delivery semantics |
MQTTium keeps protocol state in a synchronous state machine and leaves sockets, timers, callbacks, and task ownership to the asyncio adapter. That separation makes QoS transitions and rollback independently testable while keeping the native client free of background threads.
Install
python -m pip install mqttium
First round trip
The example subscribes, publishes at QoS 1, waits for PUBACK, and consumes the message:
import asyncio
from mqttium.api import AsyncClient
async def main() -> None:
client = AsyncClient("example-client")
try:
await client.connect("127.0.0.1", 1883)
await client.subscribe("devices/+/status", qos=1)
receipt = await client.publish(
"devices/demo/status",
b"online",
qos=1,
)
await receipt.wait()
async for message in client.messages():
print(message.topic, message.payload)
break
finally:
await client.disconnect()
asyncio.run(main())
For QoS 0, a receipt completes after writer admission because MQTT provides no
broker acknowledgement. QoS 1 completes on PUBACK; QoS 2 completes on PUBCOMP.
Waiting for publish() and waiting for receipt.wait() therefore answer
different questions.
Backpressure is part of the API
publish() waits for capacity by default. Applications that have a defined
shed, retry, or spill policy can request immediate refusal:
from mqttium import FlowControlError
from mqttium.api import AsyncClient
client = AsyncClient(publish_backpressure="error")
try:
receipt = await client.publish("telemetry", payload, qos=1)
except FlowControlError:
await shed_or_retry(payload)
Outbound protocol state, encoded writes, inbound protocol state, and delivery
queues have independent bounds because they have different lifetimes. Passing
None disables an optional bound and should be a deliberate capacity decision.
For a sustained producer, publish_many() consumes an iterable in bounded
chunks and returns one aggregate receipt:
from mqttium.api import PublishMessage
batch = await client.publish_many(
PublishMessage("telemetry", sample, qos=1) for sample in samples
)
await batch.wait()
Reconnect and durable sessions
Automatic reconnect is opt-in through ReconnectPolicy. Durable recovery also
requires a durable broker session; storing client-side inflight state alone is
not sufficient.
from mqttium import MQTTProtocolVersion
from mqttium.api import AsyncClient, Properties, ReconnectPolicy
from mqttium.persistence import SqliteInflightStore
store = SqliteInflightStore("mqtt-session.sqlite")
client = AsyncClient(
"gateway",
protocol=MQTTProtocolVersion.MQTTv5,
clean_start=False,
connect_properties=Properties({"session_expiry_interval": 86_400}),
reconnect=ReconnectPolicy(max_retries=None),
store=store,
)
SqliteInflightStore persists unfinished outbound QoS 1/2 exchanges and
inbound QoS 2 protocol state. It does not persist arbitrary application work,
delivered callback/iterator queues, or subscription intent. The application
owns the store and must close it after the client has shut down.
Paho migration
New async applications should use AsyncClient. MQTTium also ships a
Provisional, Paho-shaped CallbackAPIVersion.VERSION2 facade for existing
synchronous applications that need an incremental migration path. It is tested
and bounded, but it is not a drop-in promise, a performance-parity promise, or
a second native API. See Migrating from Paho
and the exact compatibility matrix.
Documentation
The complete documentation is available on Read the Docs.
| Start here | Use it for |
|---|---|
| Getting started | Installation, lifecycle, publishing, subscribing, and delivery |
| Configuration and sizing | Choosing queue, byte, inflight, timeout, and reconnect settings |
| Sessions and persistence | Broker sessions, reconnect, SQLite, and restart recovery |
| Transports and security | TCP, TLS, WebSocket, Unix sockets, and credential handling |
| MQTT 5 | Properties, authentication, topic aliases, and negotiated limits |
| Operations | Runtime snapshots, pressure diagnosis, and graceful shutdown |
| Stable API reference | Supported imports, signatures, defaults, and exceptions |
| Compatibility matrix | Python, platform, broker, protocol, and transport validation |
Architecture, conformance, stability tiers, benchmarking methodology, and release evidence are documented separately so current contracts are not mixed with historical reports.
Performance claims
Performance is treated as an evidence discipline, not a slogan. Changes must preserve MQTT semantics, bounded memory, backpressure, and event-loop fairness. The benchmarking contract defines valid comparisons. Cross-client results will be linked only after the independent benchmark repository publishes reviewed MQTTium, Paho, and gmqtt runs with exact versions, environment details, raw artifacts, comparable completion semantics, and stated limitations.
Support and contributing
- Read the support policy before requesting usage help.
- Use the structured issue form for reproducible bugs.
- Report vulnerabilities privately as described in the security policy.
- See the contribution guide for development and validation commands.
MQTTium is original software licensed under Apache-2.0. Paho and gmqtt are referenced only for migration, interoperability, and independent comparison.
Release files for mqttium 1.0.0rc12
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mqttium-1.0.0rc12.tar.gz | 854.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mqttium-1.0.0rc12-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.0 MB
Release files / mqttium-1.0.0rc12.tar.gz
| Download URL | mqttium-1.0.0rc12.tar.gz |
|---|---|
| Size | 854.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc2d3cecd24e19eb71b15bd445990e5943cc833dc7a8cb76585744747180d85a
|
|
BLAKE2b-256 checksum How to use checksums |
57490b12944ed2fbb7880cd5beec8ab9ac6eb8e808133186cae7a23f9c6df1cd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logRelease files / mqttium-1.0.0rc12-py3-none-any.whl
| Download URL | mqttium-1.0.0rc12-py3-none-any.whl |
|---|---|
| Size | 182.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
49fc4ff6b8adaedb285dda3564c617c4ba1c580a1abadd2722c6d4673aea702d
|
|
BLAKE2b-256 checksum How to use checksums |
bd09bf38e427d4470480a885ec4fbfaf620aa26fdbf51f640f357f6074826ac9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency log