llama
An opinionated library for writing services on a MQTT message bus.
Why?
Something along the lines of: After implementing DaliQTT I wanted something more generalized to create new services more easily.
Also see Alpaca, the Go implementation of this library.
Installation
The package is available via pypi as llama-mqtt, so for installation just type:
pip3 install llama-mqtt
How to use
Creating a new service in your network is now as easy as:
# Connect to MQTT broker and start dispatch loop
dispatch, receive = mqtt.connect("localhost:1883", {
"strings": "v1/simple/strings",
})
handle(dispatch, receive())
With a handler like
def handle(dispatch, actions):
"""Process incoming actions"""
for action in actions:
if action["type"] == REVERSE_REQUEST:
dispatch(_handle_reverse(action["payload"]))
The receive function can be used in a blocking and non-blocking fashion by passing a timeout in seconds (e.g. receive(timeout=0.25) and it can be used in a one shot kind of way, by passing once=True.
This way receive(once=True) will block until an action is received, or (if specified) the timeout will occure.
Error handling
In case decoding the MQTT payload failed, an llama.actions.MESSAGE_DECODE_ERROR_RESULT is received.
Example
For a simple working example please checkout the examples/reverser/reverser.py string reversal service.
Metadata
Release files for llama-mqtt 0.5.0
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 |
|---|---|---|---|---|
| llama-mqtt-0.5.0.tar.gz | 5.2 kB | Without provenance | Details for llama-mqtt-0.5.0.tar.gz |
Release files / llama-mqtt-0.5.0.tar.gz
| Download URL | llama-mqtt-0.5.0.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
65813aeb7bcdddb46ed546e5039da37569fcdab1cdd6aaccd463edd08fe7cb12
|
|
BLAKE2b-256 checksum How to use checksums |
80c7e348f90a987b7785752f70fcf50fbf634349df74122803daaa471810d9de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for llama-mqtt 0.5.0
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.