Skip to main content

An opinionated library for writing MQTT services

Project description

An opinionated library for writing services on a MQTT message bus.


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.


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:

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.


For a simple working example please checkout the examples/reverser/ string reversal service.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for llama-mqtt, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size llama-mqtt-0.5.0.tar.gz (5.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page