trio async MQTT Client
Project description
trio_paho_mqtt
trio specific async MQTT client. The goal of this project is to have all the MQTT protocol stuff handled by paho-mqtt, while the async loopy stuff is handled by trio. This keeps our MQTT communication async, without having to shove paho-mqtt into a thread, and without having to reimplement the MQTT protocol.
All callbacks are also removed to be more trio-like. Messages are accessed through an async for
loop.
This is meant to be a light-as-possible wrapper around paho-mqtt. That way if something goes wrong with MQTT message parsing, it's not my fault ;-)
Usage
First, see the example.py
and paho-mqtt documentation.
The goal is to expose all the same methods as the paho-mqtt Client
. If any methods (besides callbacks) are missing
or do something unexpected, this is a bug. Please open an issue.
AsyncClient
is initialized with a sync mqtt.Client
and a trio.Nursery
but then otherwise should operate much
like the sync Client
. Methods are not coroutines, they are non-blocking functions, so you do not need to call
await
. The only exception is accessing messages through async for
.
Example
import paho.mqtt.client as mqtt
import trio
from trio_paho_mqtt import AsyncClient
async def handle_messages(client):
async for msg in client.messages():
print(f"Received msg: {msg}")
async with trio.open_nursery() as nursery:
sync_client = mqtt.Client()
client = AsyncClient(sync_client, nursery)
client.connect('mqtt.eclipse.org', 1883, 60)
client.subscribe(topic)
client.publish(topic, msg)
nursery.start_soon(handle_messages, client)
Related projects
- gmqtt - Uses asyncio and callbacks. Isn't compatible with trio.
- hbmqtt - Uses asyncio. Reimplements the MQTT protocol.
- aiomqtt - Uses asyncio and wraps paho, but still uses the loop from paho-mqtt. I believe all operations are put into a worker thread.
- distmqtt - anyio-ified hbmqtt fork. Works with trio.
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 trio-paho-mqtt-0.3.1.tar.gz
.
File metadata
- Download URL: trio-paho-mqtt-0.3.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fc416d663856bdeb2beae96d81ee2e82cf98b2cadc8ecc3e033137afacb45ae |
|
MD5 | a2e62142b61f13b0e3aa927468cd7156 |
|
BLAKE2b-256 | 80ae363804eca1c5cbc9bceb8a1f79ae46a1db4cfb9180374d7d7a8720c819dd |
File details
Details for the file trio_paho_mqtt-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: trio_paho_mqtt-0.3.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57405e1ec5b195e6760da9f5a4b1b00e201ec7aed787f6267f6361bf00a63c53 |
|
MD5 | 09fb6783080959b73dcd8ea67403da85 |
|
BLAKE2b-256 | 9c6797686043cce5c8e068ef2fb82315b3419215a71fb53a12012ae725cb8fe2 |