A sans-I/O implementation of the MQTTv5 protocol for Python, written in Rust. Serialization is ~5x faster and deserialization ~20x faster than comparable Python code (benchmarked against mqttproto).
Reading/Writing a QoS=1 Publish packet with a 256 bytes payload.
Write a packet
import mqtt5
packet = mqtt5.ConnectPacket(client_id="Bulbasaur")
data = packet.write()
Read a packet
import mqtt5
buffer = bytearray(b"\x20\x03\x00\x00\x00")
packet, nbytes = mqtt5.read(buffer)
pip install mqtt5
Note that mqtt5 implements only the low-level packet de/serialization. If you're looking for a complete MQTT client, check out aiomqtt.
See the stub file for an API reference and the MQTTv5 specification for details about the de/serialization.
Invalid packets raise exceptions rather than being silently ignored or partially parsed.
This project adheres to Semantic Versioning.
See CHANGELOG.md, which follows the principles of Keep a Changelog.
mqtt5 was inspired by Brett Cannon's sans-I/O documentation. I've also learned a lot from Alex Grönholm's mqttproto, which is an excellent pure-Python MQTTv5 protocol implementation.