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.connect_callback_set(lambda *_: client.subscribe("#", qos=1))
client.message_callback_set(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).
Losers excluded:
benchmark.csv
Module;Time;RSS
ctypes_mosq;4.44;7900
ctypes_mosq_async;8.54;14672
paho;8.74;13004
gmqtt;3.54;12136
mqttools;11.39;15716
aiomqtt;147.40;302936
amqtt;90.32;469020
License
MIT
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.2.0.tar.gz
(17.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ctypes_mosquitto-0.2.0.tar.gz.
File metadata
- Download URL: ctypes_mosquitto-0.2.0.tar.gz
- Upload date:
- Size: 17.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa4c37acf036502023970190bd8fd0200079e871a934c77419758d02adccd5f6
|
|
| MD5 |
e8cd152ac38537f0f86224c4a78b371c
|
|
| BLAKE2b-256 |
92a12d83c00857c8ab6cc7a4cfafcc575be7cac292df8130bbddde4bb794ff0f
|
File details
Details for the file ctypes_mosquitto-0.2.0-py3-none-any.whl.
File metadata
- Download URL: ctypes_mosquitto-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d1bb9df98d3d5fc11843e74fe52b6c435fc5acecf5cac055bb3144b89d16a26
|
|
| MD5 |
d0085b864bb42dc230cb1a1d046b5768
|
|
| BLAKE2b-256 |
cc62b5e9a70ab7fafe8f5433e92aab62889e69b8f95ce59f24c6a6de306a2bc8
|