Skip to main content

A lightweight Python MQTT client implemented as a binding to libmosquitto via ctypes.

Project description

ctypes-mosquitto

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

Dependencies

  • python3.8+
  • libmosquitto1

Installation

  • pip install ctypes-mosquitto

Usage

from ctypes_mosquitto import Mosquitto


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


client = Mosquitto()
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 ctypes_mosquitto.aio import AIO
from ctypes_mosquitto import Mosquitto


async def main():
    async with AIO(Mosquitto()) 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 directory.

Benchmarks

Receiving one million messages with QoS 0.

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

benchmark-results

Losers excluded:

benchmark-results-fast

benchmark.csv

Module;Time;RSS
ctypes_mosq;4.64;8064
ctypes_mosq_async;9.91;14660
paho;8.80;12960
gmqtt;3.45;12044
mqttools;6.22;15704
aiomqtt;55.93;567444
amqtt;70.37;694336

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

ctypes_mosquitto-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

ctypes_mosquitto-0.1.0-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file ctypes_mosquitto-0.1.0.tar.gz.

File metadata

  • Download URL: ctypes_mosquitto-0.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for ctypes_mosquitto-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6ec526054f9c944ebc51d05a24c02f948c83cfb4f635c383f20f2d5838c06a1d
MD5 bde559c428a70426bbc871581dfc042f
BLAKE2b-256 0e98acb9963392565bbbb634d129c836e5a6e5f167787cdde5a29a4ff1c28508

See more details on using hashes here.

File details

Details for the file ctypes_mosquitto-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ctypes_mosquitto-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6317676d0ecd9f4bc2101a29ec3b01b819f894e50f5b0c4489941f4dce2e457e
MD5 4173151f4d733a282e97fec27aa28fd3
BLAKE2b-256 b86024bf879a913537e58769d077bc60e85533cf28d64aa37298c974fe5ffcbf

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