This release is a pre-release and may not be stable for production use.
MQTTium
MQTTium is a reliable, async-native MQTT client for modern Python.
It combines a synchronous protocol engine with an asyncio API, bounded
backpressure, durable inflight persistence, explicit delivery receipts, and
complete MQTT QoS state machines.
Status: alpha (
0.1.0a4). The implementation is extensively tested, but the public API may still change before the first stable release.
Features
- MQTT 3.1.1 and MQTT 5;
- QoS 0, 1 and 2 with one authoritative protocol state machine;
- TCP, TLS, WebSocket and Unix transports;
- reconnect and session replay;
- bounded callback and async-iterator delivery;
- immutable runtime statistics for queues, budgets, receipts and transports;
- manual acknowledgement;
- in-memory and SQLite inflight persistence;
- aggregate
publish_many()with bounded memory and measured throughput gains; - synchronous loop-bound
publish_nowait()for non-suspending native producers; - an additive Paho VERSION2 compatibility façade, isolated from the native API;
- inline type information for type checkers.
Python 3.11–3.14 is supported. MQTTium is licensed under Apache-2.0.
Installation
python -m pip install mqttium
To work on the unreleased development version:
git clone https://github.com/yoch/mqttium.git
cd mqttium
python -m pip install -e ".[dev,fuzz,release]"
Quick start
import asyncio
from mqttium.api import AsyncClient
async def main() -> None:
client = AsyncClient("demo-client")
await client.connect("127.0.0.1", 1883)
await client.subscribe("demo/#")
receipt = await client.publish("demo/hello", b"world", qos=1)
await receipt.wait()
await client.disconnect()
asyncio.run(main())
Non-suspending publishing
A producer already executing on the client's event loop can submit without creating or awaiting a coroutine:
receipt = client.publish_nowait("telemetry/device-1", payload, qos=1)
# Continue synchronously, then observe completion later if needed.
await receipt.wait()
publish_nowait() either admits the publication immediately or raises
FlowControlError; it never waits for engine or writer capacity. It returns the
normal PublishReceipt, so QoS 1/2 completion is observed in the same way as
with publish().
The method follows the same ownership rule as asyncio.Queue.put_nowait(): it
is intended for the client's owning event-loop thread, not as a generic
thread-safe API. Cross-thread synchronous callers should use an adapter such as
mqttium.compat.paho.Client, which coalesces submissions before handing a
bounded batch to the loop.
Batched publishing
publish_many() consumes iterables in bounded chunks and returns one aggregate
receipt rather than creating one task or event per message:
from mqttium.api import PublishMessage
batch = await client.publish_many(
PublishMessage("telemetry/device-1", payload, qos=1)
for payload in payloads
)
await batch.wait()
The retained paired A/B benchmark measured publisher-throughput geomean
improvements of 36.9% for QoS 0, 15.9% for QoS 1, and 7.0% for QoS 2
against equivalent individual publishing pipelines on the validated source
tree. Benchmark methodology and limitations are documented in
docs/BENCHMARKING.md.
Bounded memory
Every queue that can grow with application load is bounded by default, so a producer that outruns its broker is slowed down rather than allowed to exhaust the process:
client = AsyncClient(
max_pending_outbound_messages=10_000, # unfinished QoS 1/2 publications
max_pending_outbound_bytes=64 * 1024**2, # their logical topic+payload+properties
max_pending_delivery_bytes=64 * 1024**2, # inbound messages awaiting a consumer
max_ingress_batch_bytes=1 * 1024**2, # decoded work before delivery is drained
publish_backpressure="wait", # or "error" to refuse immediately
)
publish() waits for capacity by default and raises FlowControlError under
publish_backpressure="error" or with nowait=True. A refusal is atomic: no
packet identifier is allocated and no store record is written. Pass None for
any limit to restore unbounded queueing.
These defaults are new in 0.1.0a2; before them a QoS 1/2 producer could queue
until the 65 535 packet-identifier space was exhausted. See
docs/MIGRATION.md.
Runtime statistics
stats() returns a frozen snapshot without starting a sampler or emitting logs:
snapshot = client.stats()
print(snapshot.outbound.pending_bytes)
print(snapshot.inbound.inflight)
print(snapshot.writer.queued_bytes)
print(snapshot.delivery.pending_bytes)
Each section is produced by the component that owns the state — the two protocol
sessions, the effect and write pumps, the transport — and stats() only
assembles them. The snapshot also includes lifetime high-water marks, batching
decision counters, task state, receipt counts, decoder buffering and
WebSocket/stream transport buffers. It is intended to be called on the client's
owning event loop. See docs/API-STABILITY.md.
Validation
The release gates include:
- more than 300 unit tests;
- Mosquitto integration tests on Python 3.11, 3.12, 3.13 and 3.14;
- deterministic and Hypothesis-based fuzzing;
- Ruff formatting and linting;
- mypy validation and a PEP 561
py.typedmarker; - an 80% coverage gate;
- wheel, source-distribution and isolated-install validation;
- delivery, persistence, TCP, TLS and WAN-profile benchmarks.
A separate finalisation workflow runs short reconnect/backpressure soaks on
Linux for relevant pull requests. Extended Linux/macOS soaks and interoperability
campaigns against multiple brokers are available by manual dispatch. Their
acceptance criteria are documented in docs/STABILITY.md.
Documentation
docs/DESIGN.md— architecture and invariantsdocs/API-STABILITY.md— public API candidate and deprecationsdocs/STABILITY.md— soak and interoperability campaigndocs/IMPLEMENTATION-GUIDE.md— protocol contractsdocs/COMPAT.md— Paho compatibility surfacedocs/MIGRATION.md— migration guidancedocs/BENCHMARKING.md— benchmark validity contractdocs/FUZZING.md— fuzzing strategydocs/ROADMAP.md— remaining stable-release workPROVENANCE.md— source history and licensing review
Contributing and security
See CONTRIBUTING.md. Report vulnerabilities through the
private process described in SECURITY.md.
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 mqttium-0.1.0a4.tar.gz.
File metadata
- Download URL: mqttium-0.1.0a4.tar.gz
- Upload date:
- Size: 261.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80e4f02b99ce0f109eb52aa97f4007cc60cd19e177f43c97d950606486e53665
|
|
| MD5 |
887b7638f8ea617be0a2a1751c71383e
|
|
| BLAKE2b-256 |
80e6e8493619168308e7cce5ca05f8d3ba21c19af499836cce034068d44fe8ed
|
Provenance
The following attestation bundles were made for mqttium-0.1.0a4.tar.gz:
Publisher:
publish.yml on yoch/mqttium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mqttium-0.1.0a4.tar.gz -
Subject digest:
80e4f02b99ce0f109eb52aa97f4007cc60cd19e177f43c97d950606486e53665 - Sigstore transparency entry: 2350968744
- Sigstore integration time:
-
Permalink:
yoch/mqttium@541af7621f1213bb1a8e67405adecc025682d688 -
Branch / Tag:
refs/tags/v0.1.0a4 - Owner: https://github.com/yoch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@541af7621f1213bb1a8e67405adecc025682d688 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mqttium-0.1.0a4-py3-none-any.whl.
File metadata
- Download URL: mqttium-0.1.0a4-py3-none-any.whl
- Upload date:
- Size: 118.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b63510a4d7375cba50d84cef64f69cb09586338ad8f277097b5e213dcf0dcff
|
|
| MD5 |
2e1283f103c6f6c65908276a3c22e386
|
|
| BLAKE2b-256 |
48bb15f66260b4c84b430d95862b48a61e163edf08430847b640d40a7ac8d972
|
Provenance
The following attestation bundles were made for mqttium-0.1.0a4-py3-none-any.whl:
Publisher:
publish.yml on yoch/mqttium
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mqttium-0.1.0a4-py3-none-any.whl -
Subject digest:
5b63510a4d7375cba50d84cef64f69cb09586338ad8f277097b5e213dcf0dcff - Sigstore transparency entry: 2350968790
- Sigstore integration time:
-
Permalink:
yoch/mqttium@541af7621f1213bb1a8e67405adecc025682d688 -
Branch / Tag:
refs/tags/v0.1.0a4 - Owner: https://github.com/yoch
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@541af7621f1213bb1a8e67405adecc025682d688 -
Trigger Event:
release
-
Statement type: