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.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.26;18316
pymosq_async;0:09.36;24852
paho;0:09.06;23556
gmqtt;0:04.33;25176
mqttools;0:06.72;28116
aiomqtt;0:53.69;578288
amqtt;1:06.86;736724

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.2.tar.gz (11.9 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.2-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymosquitto-0.2.2.tar.gz
  • Upload date:
  • Size: 11.9 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.2.tar.gz
Algorithm Hash digest
SHA256 07048cfdfe4a4d9443363bd1d3cb096e8f3c9f40cf882a81889839c6b7d43eef
MD5 d41bfc3f5e989fcaa77d31160f3bc9f6
BLAKE2b-256 7b06478930acd8e1e1d4259a7bcd2adc253196cd4f901e8c46d973f2bd4852e3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pymosquitto-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9e0f5062d74ec7d39152c725d268bff8167e6007428b112e724f9477a50edf83
MD5 63763093b43d26d2e8f10a775d981f12
BLAKE2b-256 18b8710ce1ccbbf120e254caaddff410554c85b05b75de0b93e747937af588eb

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