https://github.com/mozanunal/mqtt_decorator
mqtt_decorator is a decorator module that converts MQTT subscriptions and messages to a flask like API.
https://github.com/mozanunal/mqtt_decorator
converts-mqtt-subscriptions flask mqtt-decorator
Last synced: 2 months ago
JSON representation
mqtt_decorator is a decorator module that converts MQTT subscriptions and messages to a flask like API.
- Host: GitHub
- URL: https://github.com/mozanunal/mqtt_decorator
- Owner: mozanunal
- License: gpl-3.0
- Created: 2020-05-17T16:14:25.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-08T14:10:27.000Z (over 4 years ago)
- Last Synced: 2025-12-28T18:53:40.506Z (6 months ago)
- Topics: converts-mqtt-subscriptions, flask, mqtt-decorator
- Language: Python
- Homepage:
- Size: 49.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG
- License: LICENSE
Awesome Lists containing this project
README
# mqtt_decorator
[](https://github.com/mozanunal/mqtt_decorator/actions/workflows/autopep8.yml)
[](https://github.com/mozanunal/mqtt_decorator/actions/workflows/pylint.yml)
[](https://github.com/mozanunal/mqtt_decorator/actions/workflows/pytest.yml)
mqtt_decorator is a decorator module which converts mqtt subscriptions and messages to a [Flask](https://flask.palletsprojects.com/en/1.1.x/) like api.
### Installing
The package can be installed via pip
```
pip install mqtt_decorator
```
### Demo
```python
from mqtt_decorator import MqttDecorator
import paho.mqtt.client as mqtt
# you can specify all
# paho mqtt client options
# such as websocket connections or
# tls connections
mqttc = mqtt.Client(clean_session=True)
app = MqttDecorator(mqttc)
@app.route("$SYS//")
def broker_url_params(msg, broker, type):
print("---broker_url_params", msg.topic, msg.payload)
print("--broker", broker)
print("--type", type)
@app.route("$SYS/broker/version")
def version(msg):
print("---version", msg.topic, msg.payload)
@app.route("$SYS/broker/uptime")
def uptime(msg):
print("---uptime", msg.topic, msg.payload)
if __name__ == "__main__":
app.run( "mqtt.eclipse.org", 1883 )
```
### Development
In this repo issue based development is active. For any problems or new enhancements please open a issue.
Create virtual environment (It should be done only for first installation)
```
conda create -n mqtt_decorator python=3.8
```
Activate virtual environment
```
conda activate mqtt_decorator
```
Install this package
```
pip install -e .
```
Autopep8 is used for formatting.
```
autopep8 -r -i mqtt_decorator test
```
Pylint is used for linting.
```
pylint mqtt_decorator
```
### Docs
for the first time
```
sphinx-apidoc -F mqtt_decorator -o docs/source
```
just update the auto docs
```
sphinx-apidoc -f mqtt_decorator -o docs/source
```
### Deployment
The following 2 commands are required to deploy over pypi.
```
python setup.py sdist bdist_wheel
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
```
### Licence
GPL
### Acknowledges
This package is developed using
- Python <3
- Paho-Mqtt
Heavily inspired from
- [Flask](https://flask.palletsprojects.com/en/1.1.x/)
### Contributors
- [mozanunal](https://github.com/mozanunal)