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 import Client


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


client = Client()
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 AsyncClient


async def main():
    async with AsyncClient() as client:
        await client.connect("localhost", 1883)
        await client.subscribe("#", 1)
        async for msg in client.read_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.23;18552
pymosq_async;0:09.39;25004
paho;0:08.84;23544
gmqtt;0:03.97;24780
mqttools;0:06.49;27944
aiomqtt;0:53.48;578296
amqtt;1:02.94;756716

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.3.tar.gz (12.2 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.3-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymosquitto-0.2.3.tar.gz
  • Upload date:
  • Size: 12.2 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.3.tar.gz
Algorithm Hash digest
SHA256 eb156e476c647074db6a4e99982a0691a66665ab787127ce2435bac91bedc742
MD5 839d90b05ada2733bbfa3e7b1b723bfc
BLAKE2b-256 595ad35df9ef62f69115f716a087b73a2d982778a7e5874c29758fd43f2e6b16

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymosquitto-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 10.8 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 08e37f0da374af8a92de16ff99da8c510b0bc53d8667b0133510976f0d3b61d4
MD5 958f91e7848082c2414c09d4c5460629
BLAKE2b-256 6a28809d8decc783c95ddeaec2cc90a8cd9f67a8bfef007824c09c0d2eff6614

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