{ "info": { "author": "Ubidots Team", "author_email": "devel@ubidots.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: System :: Hardware" ], "description": "===================================\nUbidots Python API Client\n===================================\n\nThe Ubidots Python API Client makes calls to the `Ubidots Api `_. The module is available on `PyPI `_ as \"ubidots\".\n\nTo follow this quickstart you'll need to have python 2.7 in your machine (be it a computer or an python-capable device), which you can download at ``_.\n\n\nInstalling the Python library\n-----------------------------\n\nUbidots for python is available in PyPI and you can install it from the command line:\n\n.. code-block:: bash\n\n $ pip install ubidots==1.6.6\n\nDon't forget to use sudo if necessary.\n\nYou can install pip in Linux and Mac using this command:\n\n.. code-block:: bash\n\n $ sudo easy_install pip\n\nIf you don't have *easy_install*, you can get it through *apt-get* on Debian-based distributions:\n\n.. code-block:: bash\n \n $ sudo apt-get install python-setuptools\n\nIf you are using Microsoft Windows you can install pip from `here `_.\n\n\nConnecting to the API\n----------------------\n\nBefore playing with the API you must be able to connect to it using an API token, which can be found `in your profile `_.\n\nIf you don't have an account yet, you can `create one here `_.\n\nOnce you have your token, you can connect to the API by creating an ApiClient instance. Let's assume your token is: \"f9iP6BpxpviO06EbebukACqEZcQMtM\". Then your code would look like this:\n\n\n.. code-block:: python\n\n from ubidots import ApiClient\n\n api = ApiClient(token='f9iP6BpxpviO06EbebukACqEZcQMtM')\n\n\nNow you have an instance of ApiClient (\"api\") which can be used to connect to the API service.\n\nSaving a Value to a Variable\n----------------------------\n\nRetrieve the variable you'd like the value to be saved to:\n\n.. code-block:: python\n\n my_variable = api.get_variable('56799cf1231b28459f976417')\n\nGiven the instantiated variable, you can save a new value with the following line:\n\n.. code-block:: python\n\n new_value = my_variable.save_value({'value': 10})\n\nYou can also specify a timestamp (optional):\n\n.. code-block:: python\n\n new_value = my_variable.save_value({'value': 10, 'timestamp': 1376061804407})\n\nIf no timestamp is specified, the API server will assign the current time to it. We think it's always better for you to specify the timestamp so the record reflects the exact time the value was captured, not the time it arrived to our servers.\n\nCreating a DataSource\n----------------------\n\nAs you might know by now, a data source represents a device or a virtual source.\n\nThis line creates a new data source:\n\n.. code-block:: python\n\n new_datasource = api.create_datasource({\"name\": \"myNewDs\", \"tags\": [\"firstDs\", \"new\"], \"description\": \"any des\"})\n\n\nThe 'name' key is required, but the 'tags' and 'description' keys are optional. This new data source can be used to track different variables, so let's create one.\n\n\nCreating a Variable\n--------------------\n\nA variable is a time-series containing different values over time. Let's create one:\n\n\n.. code-block:: python\n\n new_variable = new_datasource.create_variable({\"name\": \"myNewVar\", \"unit\": \"Nw\"})\n\nThe 'name' and 'unit' keys are required.\n\nSaving Values in Bulk\n---------------------\n\nThis method used the \"collections\" API endpoints: http://ubidots.com/docs/api/v1_6/collections\n\nTo save several values to a single variable:\n\n.. code-block:: python\n\n new_variable.save_values([\n {'timestamp': 1380558972614, 'value': 20},\n {'timestamp': 1380558972915, 'value': 40},\n {'timestamp': 1380558973516, 'value': 50},\n {'timestamp': 1380558973617, 'value': 30}\n ])\n\nTo update several variables in a single request:\n\n.. code-block:: python\n\n api.save_collection([{'variable': '557f686f7625426a41a42f49', 'value': 10}, {'variable': '557f68747625426b97263cba', 'value':20}])\n\n\nGetting Values\n--------------\n\nTo get the values of a variable, use the method get_values in an instance of the class Variable. This will return a list like object with an aditional attribute items_in_server that tells you how many values this variable has stored on the server.\n\nIf you only want the last N values call the method with the number of elements you want.\n\n.. code-block:: python\n\n # Getting all the values from the server. WARNING: If your variable has millions of datapoints, then this will take forever or break your code!\n all_values = new_variable.get_values()\n \n # If you want just the last 100 values you can use:\n some_values = new_variable.get_values(100)\n\nGetting the Last Value of a Variable\n------------------------------------\n\nTo get the last value of a variable, get a single item in the get_values method:\n\n.. code-block:: python\n\n last_value = new_variable.get_values(1)\n\nThen select the first item of the list (last_value[0]), which is a dict, and retrieve the \"value\" key:\n\n.. code-block:: python\n\n print last_value[0]['value']\n \n # Then you can read this value and do something:\n \n if last_value[0]['value']:\n print \"Switch is ON\"\n else:\n print \"Switch is OFF\"\n\nGetting a group of Data sources\n--------------------------------\n\nIf you want to get all your data sources you can a method on the ApiClient instance directly. This method return a Paginator object which you can use to iterate through all the items.\n\n.. code-block:: python\n \n # Get all datasources\n all_datasources = api.get_datasources()\n \n # Get the last five created datasources\n some_datasources = api.get_datasources(5)\n\n\nGetting a specific Data source\n-------------------------------\n\nEach data source is identified by an ID. A specific data source can be retrieved from the server using this ID.\n\nFor example, if a data source has the id 51c99cfdf91b28459f976414, it can be retrieved as follows:\n\n\n.. code-block:: python\n\n my_specific_datasource = api.get_datasource('51c99cfdf91b28459f976414')\n\n\nGetting a group of Variables from a Data source\n-------------------------------------------------\n\nWith a data source. you can also retrieve some or all of its variables:\n\n.. code-block:: python\n\n # Get all variables\n all_variables = datasource.get_variables()\n \n # Get last 10 variables\n some_variables = datasource.get_variables(10)\n\n\nGetting a specific Variable\n------------------------------\n\nAs with data sources, you can use your variable's ID to retrieve the details about it:\n\n.. code-block:: python\n\n my_specific_variable = api.get_variable('56799cf1231b28459f976417')\n\n\nManaging HTTP Exceptions\n-------------------------\n\nGiven that possibility that a request to Ubidots could result in an error, the API client bundles some exceptions to make easier to spot the problems. All exceptions inherit from the base UbidotsError. The full list of exceptions is:\n\nUbidotsError400, UbidotsError404, UbidotsError500, UbidotsForbiddenError, UbidotsBulkOperationError\n\nEach error has an attribute 'message' (a general message of the error) and 'detail' (usually JSON from the server providing more detail).\n\nYou can gaurd for these exceptions in this way:\n\n.. code-block:: python\n\n try:\n my_specific_variable = api.get_variable('56799cf1231b28459f976417')\n except UbidotsError400 as e:\n print \"General Description: %s; and the detail: %s\" % (e.message, e.detail)\n except UbidotsForbiddenError as e:\n print \"For some reason my account does not have permission to read this variable\"\n print \"General Description: %s; and the detail: %s\" % (e.message, e.detail)\n\nOther Exceptions\n----------------\n\nThere is anoter exception UbidotsInvalidInputError wich is raised when the parameters to a function call are invalid. The required fields for the parameter of each resource in this API version are:\n\nDatasource:\n Required:\n name: string.\n Optional:\n tags: list of strings.\n\n description: string.\n\nVariables:\n Required:\n name: string.\n \n unit: string.\n\nValues:\n Required:\n value: number (integer or float).\n \n variable: string with the variable of the id id.\n Optional:\n timestamp: unix timestamp.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/ubidots/ubidots-python/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "ubidots", "package_url": "https://pypi.org/project/ubidots/", "platform": "any", "project_url": "https://pypi.org/project/ubidots/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/ubidots/ubidots-python/" }, "release_url": "https://pypi.org/project/ubidots/1.6.6/", "requires_dist": null, "requires_python": null, "summary": "Api Client to connect to ubidots.com api version 1.6", "version": "1.6.6" }, "last_serial": 2140988, "releases": { "0.1.3-alpha": [ { "comment_text": "", "digests": { "md5": "1f47ed0ed56f0f147869f79091115c3f", "sha256": "17198235d7606fd2a0bc4fe3742e8a88fc3d1bae55a81cf0f26daf97806c11ac" }, "downloads": -1, "filename": "ubidots-0.1.3-alpha.tar.gz", "has_sig": false, "md5_digest": "1f47ed0ed56f0f147869f79091115c3f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4699, "upload_time": "2013-08-28T15:31:38", "url": "https://files.pythonhosted.org/packages/dc/d1/fab06e42d46987c1a7beaf54d29fd86bc3b1df3baec2c5f7d77a6bf0217b/ubidots-0.1.3-alpha.tar.gz" } ], "1.6.1": [ { "comment_text": "", "digests": { "md5": "80d03d17bc743078de0a4e584f065966", "sha256": "0469d7c0a104e215e295298ba6502021144de301b09c94c617bb93eca8cff4b8" }, "downloads": -1, "filename": "ubidots-1.6.1.tar.gz", "has_sig": false, "md5_digest": "80d03d17bc743078de0a4e584f065966", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11193, "upload_time": "2013-11-25T20:20:02", "url": "https://files.pythonhosted.org/packages/e8/03/acd8bc1795602980ff6cf445514f718b795a597206cd20a465328a992ca1/ubidots-1.6.1.tar.gz" } ], "1.6.2": [ { "comment_text": "", "digests": { "md5": "39bd521cc8e7f242cd28c0b7877ebe58", "sha256": "cf9aae4870740c00834d4430336a4bc795a6eb160f1ff431409fccd57f6253a3" }, "downloads": -1, "filename": "ubidots-1.6.2.tar.gz", "has_sig": false, "md5_digest": "39bd521cc8e7f242cd28c0b7877ebe58", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11507, "upload_time": "2015-04-30T19:37:12", "url": "https://files.pythonhosted.org/packages/dc/0e/445a7b5217bf9dc39eeec4e21ac49dbf9e46ba26d6909ec87c77a728fb4d/ubidots-1.6.2.tar.gz" } ], "1.6.3": [ { "comment_text": "", "digests": { "md5": "27180b044ab0206dd1085f518d513d11", "sha256": "b72d6b05dcebdcf18a0133fd049522ea00ca10ae53dc5784c2d1c1b9f9d4f3d5" }, "downloads": -1, "filename": "ubidots-1.6.3.tar.gz", "has_sig": false, "md5_digest": "27180b044ab0206dd1085f518d513d11", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11855, "upload_time": "2015-07-01T23:34:55", "url": "https://files.pythonhosted.org/packages/5e/09/276c992bd6a1cc20d985c39eabccb5ffa830f9fab5d70293b03d15e210ff/ubidots-1.6.3.tar.gz" } ], "1.6.4": [ { "comment_text": "", "digests": { "md5": "8370711c941cdf2b9fc3a19602e92935", "sha256": "584631dd7bd68f6e5f58eb5cf4f16a2694f0c07dd6de2972f7c3a0e2140dd8b1" }, "downloads": -1, "filename": "ubidots-1.6.4.tar.gz", "has_sig": false, "md5_digest": "8370711c941cdf2b9fc3a19602e92935", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11951, "upload_time": "2015-10-03T23:45:50", "url": "https://files.pythonhosted.org/packages/62/fa/64c2b09a103dc4ef1deacb589ddbaff189f85288e2b95bdeffdce1cea247/ubidots-1.6.4.tar.gz" } ], "1.6.5": [ { "comment_text": "", "digests": { "md5": "98cea26e6866bd5e8c96dbf65d193a47", "sha256": "d83a327357fc720c80f1da0cece2baff1d2b002a282bba542402b4b09c197639" }, "downloads": -1, "filename": "ubidots-1.6.5.tar.gz", "has_sig": false, "md5_digest": "98cea26e6866bd5e8c96dbf65d193a47", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11984, "upload_time": "2016-01-18T21:12:21", "url": "https://files.pythonhosted.org/packages/18/1c/04f717b40f6b60a5f06f6c4282c80889a3d5326f3762882f5d204df5a3ad/ubidots-1.6.5.tar.gz" } ], "1.6.6": [ { "comment_text": "", "digests": { "md5": "049e474b1c09652505a3b1e38bafe0d6", "sha256": "243e7769ab4bb8f45ba2de5e4117930121d51441ced5467f09848a62ef4c4b5e" }, "downloads": -1, "filename": "ubidots-1.6.6.zip", "has_sig": false, "md5_digest": "049e474b1c09652505a3b1e38bafe0d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16619, "upload_time": "2016-05-30T15:50:36", "url": "https://files.pythonhosted.org/packages/6a/3d/eb42deefe71193d08fcb2a8dd6943ca24d74979c64f40a4384dbfb0c9915/ubidots-1.6.6.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "049e474b1c09652505a3b1e38bafe0d6", "sha256": "243e7769ab4bb8f45ba2de5e4117930121d51441ced5467f09848a62ef4c4b5e" }, "downloads": -1, "filename": "ubidots-1.6.6.zip", "has_sig": false, "md5_digest": "049e474b1c09652505a3b1e38bafe0d6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16619, "upload_time": "2016-05-30T15:50:36", "url": "https://files.pythonhosted.org/packages/6a/3d/eb42deefe71193d08fcb2a8dd6943ca24d74979c64f40a4384dbfb0c9915/ubidots-1.6.6.zip" } ] }