Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

MQTTium logo

MQTTium

A dependable, dependency-free asyncio MQTT client for Python.

PyPI Python versions CI Coverage Documentation Apache-2.0 license

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.0rc9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mqttium 1.0.0rc9
File Size Uploaded
mqttium-1.0.0rc9.tar.gz 732.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mqttium 1.0.0rc9
File Interpreter ABI Platform
mqttium-1.0.0rc9-py3-none-any.whl Python 3 none any Details

Total release size: 905.4 kB

Release files / mqttium-1.0.0rc9.tar.gz

Download URL mqttium-1.0.0rc9.tar.gz
Size 732.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3383eddb034fa67ccbe80450ad3d80c172dcc35ec33b7223892751eb6d8c8d4e
BLAKE2b-256 checksum
How to use checksums
40921a61aebb3befd92c98380e60c1ef2476e748597708977f10b08ab60378bc
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 Aug 24, 2026.

Transparency log

Release files / mqttium-1.0.0rc9-py3-none-any.whl

Download URL mqttium-1.0.0rc9-py3-none-any.whl
Size 173.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0cda3e2c6a07f903df39062e43bdcf03719a9bf49cf2ff8160ec5ae8c640270
BLAKE2b-256 checksum
How to use checksums
46d2051953aaec722f85c7eefc2d497ed90458a7f7b5a155dcfaaee60e90185c
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 Aug 24, 2026.

Transparency log
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