PyMosquitto
A lightweight Python MQTT client implemented as a thin wrapper around libmosquitto.
It provides an efficient synchronous client (client.Mosquitto) and two variants of asynchronous clients:
aio.AsyncMosquitto- async interface to libmosquitto loop running in its own thread. It's faster, but consumes a little bit more memory.aio.TrueAsyncMosquitto- manages all events in asyncio loop by utilizingmosquitto_loop_{read,write,misc}functions.
Dependencies
- python3.8+
- libmosquitto1
Installation
- pip install pymosquitto
Usage
from pymosquitto 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 pymosquitto.aio import AsyncMosquitto
async def main():
async with AsyncMosquitto() 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.3 MB).
Losers excluded:
benchmark.csv
Module;Time;RSS
pymosq;0:04.84;18940
pymosq_async;0:08.06;25560
pymosq_true_async;0:10.78;25092
paho;0:09.07;23620
gmqtt;0:04.63;24740
mqttools;0:06.57;28068
aiomqtt;0:56.60;578380
amqtt;1:02.72;757084
License
MIT
Metadata
Release files for pymosquitto 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pymosquitto-0.4.1.tar.gz | 15.7 kB | Without provenance | Details for pymosquitto-0.4.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pymosquitto-0.4.1-py3-none-any.whl | Python 3 | none | any | Details for pymosquitto-0.4.1-py3-none-any.whl |
Total release size: 29.7 kB
Release files / pymosquitto-0.4.1.tar.gz
| Download URL | pymosquitto-0.4.1.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b22fce9a712ac08ef75e4f46d08fe6a62559503df3b2bc0637290e1e07b300a1
|
|
BLAKE2b-256 checksum How to use checksums |
f2a087711c85aa3e8a13cd38c02be9cfaf3ae9655583a200208eff8aa517d3af
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Release files / pymosquitto-0.4.1-py3-none-any.whl
| Download URL | pymosquitto-0.4.1-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
82de67039769e61c9153d069669e547274226ecb2d08820956f2a3e3533b0cc7
|
|
BLAKE2b-256 checksum How to use checksums |
eb68dd5d6e07ba62ad31d424969acff9cca6be148664a5517d3b5e0a122e4714
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.7
|
Security for pymosquitto 0.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.