Skip to main content

mqtt-codec

A weapons grade MQTT packet encoder and decoder (codec).

Status

The mqtt-codec package is an MQTT 3.1.1 packet encoder and decoder (codec). The library has high test coverage (~94%) and is known to perform well in distributed IoT networks with thousands of nodes.

Installation

The mqtt-codec package can be from pypi.org with pip:

pip install mqtt-codec

Usage

An encode/decode cycle looks like this:

>>> from io import BytesIO
>>> from binascii import b2a_hex
>>> import mqtt_codec.packet
>>> import mqtt_codec.io
>>>
>>> # Encode a Connect packet
>>> will = mqtt_codec.packet.MqttWill(qos=0, topic='hello', message='message', retain=True)
>>> connect = mqtt_codec.packet.MqttConnect(client_id='client_id', clean_session=False, keep_alive=0, will=will)
>>> with BytesIO() as f:
...   num_bytes_written = connect.encode(f)
...   buf = f.getvalue()
...
>>> assert len(buf) == num_bytes_written
>>> print('0x{} ({} bytes)'.format(b2a_hex(buf), len(buf)))
0x102500044d515454042400000009636c69656e745f6964000568656c6c6f00076d657373616765 (39 bytes)
>>>
>>> # Decode the connect packet and assert equality.
>>> with mqtt_codec.io.BytesReader(buf) as f:
...   num_bytes_read, decoded_connect = connect.decode(f)
...
>>> assert len(buf) == num_bytes_written
>>> assert connect == decoded_connect
>>> print('  Encoded {}'.format(connect))
  Encoded MqttConnect(client_id='client_id', clean_session=False, keep_alive=0, username=***, password=***, will=MqttWill(topic=hello, payload=0x6d657373616765, retain=True, qos=0))
>>> print('= Decoded {}'.format(decoded_connect))
= Decoded MqttConnect(client_id=u'client_id', clean_session=False, keep_alive=0, username=***, password=***, will=MqttWill(topic=hello, payload=0x6d657373616765, retain=True, qos=0))

Python Requirements

The mqtt-codec project has been tested on Linux against these environments:

  • Python 2.7

  • Python 3.4

  • Python 3.5

  • Python 3.6

  • Python 3.7

Python versions Python 3.0 - 3.3 may work but are not tested as part of the project continuous integration infrastructure.

Library Requirements

When running Python versions less than 3.4 the enum34 package is required. There are no other package requirements.

Project Infrastructure

The project is coordinated through public infrastructure available at several places:

Metadata

Release files for mqtt-codec 1.0.2

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

Source distribution (sdist)

Source distribution for mqtt-codec 1.0.2
File Size Uploaded
mqtt-codec-1.0.2.tar.gz 14.7 kB Details

Release files / mqtt-codec-1.0.2.tar.gz

Download URL mqtt-codec-1.0.2.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0ef4958cd37db7bfa76173abd73fc46081f2ff4297c54f3fc7853c300c1606ad
BLAKE2b-256 checksum
How to use checksums
9c2752ce163f05298f530ca115a95ed30da50db86ae51513765c4cb9328a06c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

Release history Release notifications | RSS feed

This release

1.0.2 This release

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

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