Skip to main content

No project description provided

Project description

Python MQTT framework

An MQTT listener and a friendly MQTT client.

codecov


Overview

MQTT framework is a library that provides a simple MQTT listener and a solid client. It is built on top of the paho-mqtt library.


Requirements

  • Python 3.8+

We highly recommend and only officially support the latest patch release of each Python series.

Installation

Install using pip (soon)...

pip install python-mqtt-framework

Django Integration

Add 'mqtt_framework' to your INSTALLED_APPS setting.

INSTALLED_APPS = [
    # ...
    'mqtt_framework',
]

Running the MQTT listener

To run the MQTT listener, you can use the runmqtt management command:

python manage.py runmqtt

Defining topic handlers

Within your_app/topic_handlers.py module, you'll write the topic handlers:

from mqtt_framework import TopicHandler
from rest_framework import serializers
from django.core.cache import cache
from pydantic import BaseModel


class SimpleTestModel(BaseModel):
    testing: str


class SimpleTestSerializer(serializers.Serializer):
    testing = serializers.CharField()

    def create(self, validated_data):
        cache.set('test_message', validated_data)
        return validated_data


class SerializerTopicHandler(TopicHandler):
    topic = 'test/topic'
    serializer_class = SimpleTestSerializer
    qos = 1

    # Calls the serializer's "save" method


class PydanticTopicHandler(TopicHandler):
    topic = 'another/topic'
    pydantic_model = SimpleTestModel
    qos = 0

    def handle(self):
        pydantic_instance = self.get_validated_payload()
        # Do something with the pydantic_instance

Settings

MQTT_FRAMEWORK = {
    'BROKER_URL': 'mqtt://<user>:<password>@<host>:<port>',
    'TOPIC_HANDLERS': 'your_app.topic_handlers',
    'KEEPALIVE': 60,
}

That's it, we're done!

python manage.py runmqtt

Project details


Download files

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

Source Distribution

python_mqtt_framework-0.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

python_mqtt_framework-0.0.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file python_mqtt_framework-0.0.1.tar.gz.

File metadata

  • Download URL: python_mqtt_framework-0.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.3

File hashes

Hashes for python_mqtt_framework-0.0.1.tar.gz
Algorithm Hash digest
SHA256 e7f52fcc5db70b5c917bfd9796aeb964d668bcabd09ffffa9b5adadbfb90eb23
MD5 590ac73394791756682c93b231345a47
BLAKE2b-256 bff26ca9d7370e65929233ce2f2a827c73daebea7c94a0ad631930208c3e7603

See more details on using hashes here.

File details

Details for the file python_mqtt_framework-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_mqtt_framework-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 913839a4c517963a3623a5c634ec6c54d01a253e2793c2aff97cae56c61a4fb3
MD5 1c735f0e64a95f1bc4704ba866f941a4
BLAKE2b-256 81879693940116f9849302e0d8e1e332640d7605a8bb8b4700b1354ae65870da

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page