The idiomatic asyncio MQTT client, wrapped around paho-mqtt
Project description
The idiomatic asyncio MQTT client 🙌
Documentation: https://aiomqtt.felixboehm.dev
Write code like this:
Publish
async with Client("test.mosquitto.org") as client:
await client.publish("temperature/outside", payload=28.4)
Subscribe
async with Client("test.mosquitto.org") as client:
await client.subscribe("temperature/#")
async for message in client.messages:
print(message.payload)
Key features
- No more callbacks! 👍
- No more return codes (welcome to the
MqttError
) - Graceful disconnection (forget about
on_unsubscribe
,on_disconnect
, etc.) - Supports MQTT versions 5.0, 3.1.1 and 3.1
- Fully type-hinted
- Did we mention no more callbacks?
Installation
pip install aiomqtt
The only dependency is paho-mqtt.
If you can't wait for the latest version, install directly from GitHub with:
pip install git+https://github.com/empicano/aiomqtt
Note for Windows users
Since Python 3.8, the default asyncio event loop is the ProactorEventLoop
. Said loop doesn't support the add_reader
method that is required by aiomqtt. Please switch to an event loop that supports the add_reader
method such as the built-in SelectorEventLoop
:
# Change to the "Selector" event loop if platform is Windows
if sys.platform.lower() == "win32" or os.name.lower() == "nt":
from asyncio import set_event_loop_policy, WindowsSelectorEventLoopPolicy
set_event_loop_policy(WindowsSelectorEventLoopPolicy())
# Run your async application as usual
asyncio.run(main())
License
This project is licensed under the BSD 3-clause License.
Note that the underlying paho-mqtt library is dual-licensed. One of the licenses is the Eclipse Distribution License v1.0, which is almost identical to the BSD 3-clause License. The only differences are:
- One use of "COPYRIGHT OWNER" (EDL) instead of "COPYRIGHT HOLDER" (BSD)
- One use of "Eclipse Foundation, Inc." (EDL) instead of "copyright holder" (BSD)
Contributing
We're happy about contributions to aiomqtt! 🎉 You can get started by reading CONTRIBUTING.md.
Versioning
This project adheres to Semantic Versioning. Breaking changes will only occur in major X.0.0
releases.
Changelog
See CHANGELOG.md, which follows the principles of Keep a Changelog.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiomqtt-2.3.0.tar.gz
.
File metadata
- Download URL: aiomqtt-2.3.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 312feebe20bc76dc7c20916663011f3bd37aa6f42f9f687a19a1c58308d80d47 |
|
MD5 | e23feb8ad69a1ae3a9701fb1f3c03a3c |
|
BLAKE2b-256 | dbc9168e78bd35b21d9bdbb26178db33a8f265e4a69bb4193e72434e7cb3d1cd |
File details
Details for the file aiomqtt-2.3.0-py3-none-any.whl
.
File metadata
- Download URL: aiomqtt-2.3.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 127926717bd6b012d1630f9087f24552eb9c4af58205bc2964f09d6e304f7e63 |
|
MD5 | 4c9763a24de8f2337bd71e7da4c6cc88 |
|
BLAKE2b-256 | 0d5f73aa0474a75fce798c8c45a0993720c3722688ae5bea1d0a5c4a9f97ae8e |