{ "info": { "author": "Losant", "author_email": "hello@losant.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Communications", "Topic :: Internet", "Topic :: Software Development :: Libraries" ], "description": "Losant Python MQTT Client\n=========================\n\n|travis-badge|_ |pypi-badge|_\n\n.. |travis-badge| image:: https://travis-ci.org/Losant/losant-mqtt-python.svg?branch=master\n.. _travis-badge: https://travis-ci.org/Losant/losant-mqtt-python\n\n.. |pypi-badge| image:: https://badge.fury.io/py/losant-mqtt.svg\n.. _pypi-badge: https://badge.fury.io/py/losant-mqtt\n\nThe `Losant `_ MQTT client provides a simple way for\ncustom things to communicate with the Losant platform over MQTT. You can authenticate\nas a device, publish device state, and listen for device commands.\n\nThis client works with both Python 2.7 and 3. It uses the\n`Paho MQTT Client `_ under the\ncovers for the actual MQTT communication.\n\nInstallation\n------------\n\nThe latest stable version is available in the Python Package Index (PyPi)\nand can be installed using\n\n::\n\n pip install losant-mqtt\n\n\nExample\n-------\n\nBelow is a high-level example of using the Losant Python MQTT client to send the value\nof a temperature sensor to the Losant platform.\n\n::\n\n import time\n from losantmqtt import Device\n\n # Construct device\n device = Device(\"my-device-id\", \"my-app-access-key\", \"my-app-access-secret\")\n\n def on_command(device, command):\n print(\"Command received.\")\n print(command[\"name\"])\n print(command[\"payload\"])\n\n # Listen for commands.\n device.add_event_observer(\"command\", on_command)\n\n # Connect to Losant.\n device.connect(blocking=False)\n\n # Send temperature once every second.\n while True:\n device.loop()\n if device.is_connected():\n temp = call_out_to_your_sensor_here()\n device.send_state({\"temperature\": temp})\n time.sleep(1)\n\n\nAPI Documentation\n-----------------\n\n* `Device`_\n * `constructor`_\n * `connect`_\n * `is_connected`_\n * `close`_\n * `send_state`_\n * `loop`_\n * `add_event_observer`_\n * `remove_event_observer`_\n\nDevice\n******\n\nA device represents a single thing or widget that you'd like to connect to the Losant platform.\nA single device can contain many different sensors or other attached peripherals.\nDevices can either report state or respond to commands.\n\nA device's state represents a snapshot of the device at some point in time.\nIf the device has a temperature sensor, it might report state every few seconds\nwith the temperature. If a device has a button, it might only report state when\nthe button is pressed. Devices can report state as often as needed by your specific application.\n\nCommands instruct a device to take a specific action. Commands are defined as a\nname and an optional payload. For example, if the device is a scrolling marquee,\nthe command might be \"update text\" and the payload would include the text to update.\n\nconstructor\n```````````\n\n::\n\n Device(device_id, key, secret, secure=True, transport=\"tcp\")\n\nThe ``Device()`` constructor takes the following arguments:\n\ndevice_id\n The device's ID. Obtained by first registering a device using the Losant platform.\n\nkey\n The Losant access key.\n\nsecret\n The Losant access secret.\n\nsecure\n If the client should connect to Losant over SSL - default is true.\n\ntransport\n Allowed values are \"tcp\" and \"websockets\". Defaults to \"tcp\", which is a raw TCP connection over\n ports 1883 (insecure) or 8883 (secure). When \"websockets\" is passed in, connects using MQTT over\n WebSockets, which uses either port 80 (insecure) or port 443 (secure).\n\nExample\n.......\n\n::\n\n from losantmqtt import Device\n\n device = Device(\"my-device-id\", \"my-app-access-key\", \"my-app-access-secret\")\n\nconnect\n```````\n\n::\n\n connect(blocking=True)\n\nConnects the device to the Losant platform. Hook the connect event to know when a connection\nhas been successfully established. Connect takes the following arguments:\n\nblocking\n If the connect method should block or not. True is the default, which means that the connect\n call will be a blocking call that will not return until the connection is closed or an error\n occurs - all interaction has to be done through the various event callbacks. If blocking is\n set to False, the function will only block until the connection is kicked off - after that point\n you must run the network loop yourself, by calling the `loop`_ method periodically.\n\nis_connected\n````````````\n\n::\n\n is_connected()\n\nReturns a boolean indicating whether or not the device is currently connected\nto the Losant platform.\n\nclose\n`````\n\n::\n\n close()\n\nCloses the device's connection to the Losant platform.\n\nsend_state\n``````````\n\n::\n\n send_state(state, time_like=None)\n\nSends a device state to the Losant platform. In many scenarios, device states will\nchange rapidly. For example a GPS device will report GPS coordinates once a second or\nmore. Because of this, sendState is typically the most invoked function. Any state\ndata sent to Losant is stored and made available in data visualization tools\nand workflow triggers.\n\nstate\n The state to send as a Dict.\n\ntime_like\n When the state occurred - if None or not set, will default to now.\n\nExample\n.......\n\n::\n\n device.send_state({ \"voltage\": read_analog_in() })\n\nloop\n`````\n\n::\n\n loop(timeout=1)\n\nLoops the network stack for the connection. Only valid to call when connected in non-blocking mode.\nBe sure to call this reasonably frequently when in that model to make sure the underlying\nMQTT connection does not get timed out.\n\ntimeout\n Max time to block on the socket before continuing - defaults to 1 second.\n\nadd_event_observer\n``````````````````\n\n::\n\n add_event_observer(event_name, observer)\n\nAdds an observer to listen for an event on this device.\n\nevent_name\n The event to listen for. Possible events are: \"connect\" (the device has connected),\n \"reconnect\" (the device lost its connection and reconnected),\n \"close\" (the device's connection was closed), and\n \"command\" (the device has received a command from Losant).\n\nobserver\n Callback method to call when the given event fires. The first argument for all callbacks\n will be the device instance. Command callbacks have a second argument - the command\n received.\n\n\nExample\n.......\n\n::\n\n def on_command(device, cmd):\n print(cmd[\"time\"]) # time of the command\n print(cmd[\"name\"]) # name of the command\n print(cmd[\"payload\"]) # payload of the command\n\n device.add_event_observer(\"command\", on_command)\n\nremove_event_observer\n`````````````````````\n\n::\n\n remove_event_observer(event_name, observer)\n\nRemoves an observer from listening for an event on this device.\n\nevent_name\n The event to stop listening for. Same events as `add_event_observer`_.\n\nobserver\n Callback method to remove.\n\n\nCopyright (c) 2019 Losant IoT, Inc\n\nhttps://www.losant.com\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Losant/losant-mqtt-python", "keywords": "MQTT,Losant,IoT", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "losant-mqtt", "package_url": "https://pypi.org/project/losant-mqtt/", "platform": "", "project_url": "https://pypi.org/project/losant-mqtt/", "project_urls": { "Homepage": "https://github.com/Losant/losant-mqtt-python" }, "release_url": "https://pypi.org/project/losant-mqtt/1.2.0/", "requires_dist": [ "paho-mqtt (<2,>=1.2)" ], "requires_python": "", "summary": "An MQTT client for Losant", "version": "1.2.0" }, "last_serial": 5265313, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "77f7c816a73162301268660b627b0f73", "sha256": "42e096ed418295e3e751ea1f123ecb6cc61fd408d928d8e1ca6d3d6d52394fc0" }, "downloads": -1, "filename": "losant_mqtt-1.0.0-py2.7.egg", "has_sig": false, "md5_digest": "77f7c816a73162301268660b627b0f73", "packagetype": "bdist_egg", "python_version": "2.7", "requires_python": null, "size": 10438, "upload_time": "2016-06-14T21:32:12", "url": "https://files.pythonhosted.org/packages/bb/8f/060db8f42ce57d941d9c47811050d1e1599a9ff2d506422f8f6785f59f09/losant_mqtt-1.0.0-py2.7.egg" }, { "comment_text": "", "digests": { "md5": "9c8f12ed7945505d7619e12eeb53f827", "sha256": "0f7cb78e6831c0d3e04c81cc27df35ec1cf806c94cf794be7d4830d4bef94dbe" }, "downloads": -1, "filename": "losant_mqtt-1.0.0-py3.5.egg", "has_sig": false, "md5_digest": "9c8f12ed7945505d7619e12eeb53f827", "packagetype": "bdist_egg", "python_version": "3.5", "requires_python": null, "size": 10462, "upload_time": "2016-06-14T21:32:16", "url": "https://files.pythonhosted.org/packages/f0/06/4ac4990304fe5cd1d95e4c2011e13ded37564e304d64d431e302e89914ab/losant_mqtt-1.0.0-py3.5.egg" }, { "comment_text": "", "digests": { "md5": "ae551e50684edde95194818619084ef7", "sha256": "89383622218405287f665322ec6ef0ea17d30dfc970bed7396106cb634612946" }, "downloads": -1, "filename": "losant_mqtt-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ae551e50684edde95194818619084ef7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11032, "upload_time": "2016-06-14T21:32:07", "url": "https://files.pythonhosted.org/packages/48/b5/e22c77c12b331b8135f708c207b478dbb680104d13db5e53789764a426c7/losant_mqtt-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7abafc39a821c5b155c8e193499c20d2", "sha256": "910bea67e027ee45e6e00609b6613fd200831491d6aff09b1e319617b4e582d9" }, "downloads": -1, "filename": "losant-mqtt-1.0.0.tar.gz", "has_sig": false, "md5_digest": "7abafc39a821c5b155c8e193499c20d2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8785, "upload_time": "2016-06-14T21:32:10", "url": "https://files.pythonhosted.org/packages/64/6f/7b84ac58d8e794388d6da11547d05112123ded3d665813240a6015658858/losant-mqtt-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "06558e85168c9daf574593c4ef22d893", "sha256": "64294c7f7fe0610be6d724cb3da27ca445eb94a365811e2a7cf236cca558e610" }, "downloads": -1, "filename": "losant_mqtt-1.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "06558e85168c9daf574593c4ef22d893", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12566, "upload_time": "2017-05-30T15:55:31", "url": "https://files.pythonhosted.org/packages/08/5f/50d44649dc6b5cf89face083b682040c33e5a0510d8285be84bad6ed46fd/losant_mqtt-1.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "601b91cb4e317f31b33dd7bb1db3a46a", "sha256": "3e9ae5699a12535083d9bf299e0961c25e8d32a2b3d7d0ce4684947e4ae5e8ec" }, "downloads": -1, "filename": "losant-mqtt-1.0.1.tar.gz", "has_sig": false, "md5_digest": "601b91cb4e317f31b33dd7bb1db3a46a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9025, "upload_time": "2017-05-30T15:55:34", "url": "https://files.pythonhosted.org/packages/37/42/0afb4e9f5385ca08dbf38fb56a0b268d602fa74c6b8c1f2b4797f46271b4/losant-mqtt-1.0.1.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "d7cdd67c64a115104720571a4926f0bc", "sha256": "0c1e229a93b40ae965b464e5e9f612b6876620ba067100ec56a347e7de5ab612" }, "downloads": -1, "filename": "losant_mqtt-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "d7cdd67c64a115104720571a4926f0bc", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12880, "upload_time": "2018-08-10T15:36:54", "url": "https://files.pythonhosted.org/packages/0a/8e/d5f5e3c0077e49579bac1d631050750bc0ab214a3a09f241b38ae1fc184e/losant_mqtt-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1651753ac7647b512d43bab1a9f1322a", "sha256": "c493dfc613281a8bca15c2e7835c7b866e692d3a2bfe2d08403d590a1de59286" }, "downloads": -1, "filename": "losant-mqtt-1.1.0.tar.gz", "has_sig": false, "md5_digest": "1651753ac7647b512d43bab1a9f1322a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9188, "upload_time": "2018-08-10T15:36:56", "url": "https://files.pythonhosted.org/packages/3c/68/eac719398e3ab5db4b1bba5e69615a9c9772528fdab107dadd8fb050f2c5/losant-mqtt-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "531dcbd64a0214779d1bcff1ab31d693", "sha256": "5b890fe86d418ba1f799d5db2ee659afa37dc4da23e3c31d13e0547be2ee54f7" }, "downloads": -1, "filename": "losant_mqtt-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "531dcbd64a0214779d1bcff1ab31d693", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10152, "upload_time": "2019-05-14T03:15:19", "url": "https://files.pythonhosted.org/packages/94/26/27e55f1bd02b2034456bab4d4652ef10231421702b8420a51693f7fdaa9d/losant_mqtt-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "341b6abfdc34235422bfd801e87baa2d", "sha256": "a73a9f61221fcfa45e2a87cfa4d0dbae271f07ad8a95aba3e1b708b978e74ee7" }, "downloads": -1, "filename": "losant-mqtt-1.2.0.tar.gz", "has_sig": false, "md5_digest": "341b6abfdc34235422bfd801e87baa2d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9117, "upload_time": "2019-05-14T03:15:20", "url": "https://files.pythonhosted.org/packages/95/f9/f4057f08b1d22a9a36417423bbadaed4055f60a69321cacf09b0c2cdfd1c/losant-mqtt-1.2.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "531dcbd64a0214779d1bcff1ab31d693", "sha256": "5b890fe86d418ba1f799d5db2ee659afa37dc4da23e3c31d13e0547be2ee54f7" }, "downloads": -1, "filename": "losant_mqtt-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "531dcbd64a0214779d1bcff1ab31d693", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 10152, "upload_time": "2019-05-14T03:15:19", "url": "https://files.pythonhosted.org/packages/94/26/27e55f1bd02b2034456bab4d4652ef10231421702b8420a51693f7fdaa9d/losant_mqtt-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "341b6abfdc34235422bfd801e87baa2d", "sha256": "a73a9f61221fcfa45e2a87cfa4d0dbae271f07ad8a95aba3e1b708b978e74ee7" }, "downloads": -1, "filename": "losant-mqtt-1.2.0.tar.gz", "has_sig": false, "md5_digest": "341b6abfdc34235422bfd801e87baa2d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9117, "upload_time": "2019-05-14T03:15:20", "url": "https://files.pythonhosted.org/packages/95/f9/f4057f08b1d22a9a36417423bbadaed4055f60a69321cacf09b0c2cdfd1c/losant-mqtt-1.2.0.tar.gz" } ] }