# LibMQTT [![pipeline status](https://code.tf/components/libmqtt/badges/master/pipeline.svg)](https://code.tf/components/libmqtt/commits/master) [![coverage report](https://code.tf/components/libmqtt/badges/master/coverage.svg)](http://components.pages.code.tf/libmqtt/) Lib for connecting to mosquitto in services ## Installation ```bash pip install https://code.tf/components/libmqtt/repository/master/archive.zip ``` ## Testing ```bash ./setup.py flake8 ``` ```bash ./setup.py lint ``` ```bash ./setup.py test ``` ## Usage ### Add routes ```bash mkdir transport ``` create file transport/mqtt_router.py ```python """ The dispatch function passes the following kwargs endpoint client user_data message context: is the named parameters in the path ?payload_data: is message parsed as json """ from libmqtt.router import hook_route @hook_route(('import/data',)) # hooks to given topic/topics def import_data(*args, **kwargs): # pylint: disable=unused-argument """Importing data.""" csv = kwargs.get('message').payload.decode("utf-8") ImportCsv(data=csv) kwargs['client'].publish('hello/world', 'message can be string or json') # sending {"gender": "man"} to hello/bilbo results in @hook_route(('hello/(?P+)',)) # hooks to given hello/# def import_data(*args, **kwargs): # pylint: disable=unused-argument """sending {"gender": "man} to hello/bilbo results in""" context = kwargs.get('context', {}) # is {"name": "bilbo"} data = kwargs.get('payload_data', {}) # is {"gender": "man"} ``` ### Send messages ```python >>> from libmqtt.sender import get_client >>> client.publish('/hello/world', 'message can be string or json') >>> client.loop_stop() ``` ### Start application ```python >>> from libmqtt.application import Application >>> Application('ip', 'username', 'pwd') # Will start an application and run "forever" ``` ## External packages used * [Paho-mqtt](https://www.eclipse.org/paho/) ### Testing * [flake8](http://flake8.pycqa.org/en/latest/) * [pylint](https://docs.pylint.org) * [setuptools-lint](https://pypi.python.org/pypi/setuptools-lint)