Skip to main content

A lightweight Python MQTT client implemented as a thin wrapper around libmosquitto

Project description

PyMosquitto

A lightweight Python MQTT client implemented as a thin wrapper around libmosquitto.

Dependencies

  • python3.8+
  • libmosquitto1

Installation

  • pip install pymosquitto

TODO

  • implement the remaining bindings

Usage

from pymosquitto.client import MQTTClient


def on_message(client, userdata, msg):
    print(msg)


client = MQTTClient()
client.on_connect = lambda *_: client.subscribe("#", 1)
client.on_message = on_message
client.connect_async("localhost", 1883)
client.loop_forever()

Async client example:

import asyncio

from pymosquitto.aio import AsyncMQTTClient


async def main():
    async with AsyncMQTTClient() as client:
        await client.connect("localhost", 1883)
        await client.subscribe("#", 1)
        async for msg in client.recv_messages():
            print(msg)


asyncio.run(main())

Check out more examples in tests/test_client.py.

Benchmarks

Receiving 1 million messages with QoS 0.

*The memory plots exclude the Python interpreter overhead (~10.2 MB).

benchmark-results

Losers excluded:

benchmark-results-fast

benchmark.csv

Module;Time;RSS
pymosq;0:04.33;18128
pymosq_async;0:10.34;24868
paho;0:09.15;23392
gmqtt;0:03.90;24724
mqttools;0:06.55;27860
aiomqtt;0:55.72;576700
amqtt;1:07.35;725708

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymosquitto-0.2.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymosquitto-0.2.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file pymosquitto-0.2.1.tar.gz.

File metadata

  • Download URL: pymosquitto-0.2.1.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pymosquitto-0.2.1.tar.gz
Algorithm Hash digest
SHA256 d06cd38375a11ac973b0536e3e8716fcdffbee7bf331fe9849e48c88ef0be43f
MD5 c1e56fac5fe9c7854e9f1f3afabc0f96
BLAKE2b-256 9ac8a642c1634e974be10d312834f389a253eccbeedbd6981f0138a41e147c27

See more details on using hashes here.

File details

Details for the file pymosquitto-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: pymosquitto-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for pymosquitto-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 772779405aef4e8e443e41d8fc52fb5e66a2add48a4c58f308c89a46767344ea
MD5 9cdf9e8a1f3ab7ef0acbe48f81ebf329
BLAKE2b-256 6232d846cfbbf314447bf0f99e537992496a9c7f1e740e7892977eb3d0ff7b0d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page