{"id":20260379,"url":"https://github.com/influxdata/iot-api-python","last_synced_at":"2025-04-11T01:32:31.661Z","repository":{"id":74459748,"uuid":"486734456","full_name":"influxdata/iot-api-python","owner":"influxdata","description":null,"archived":false,"fork":false,"pushed_at":"2024-05-15T17:18:52.000Z","size":101,"stargazers_count":22,"open_issues_count":5,"forks_count":11,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-03-24T22:42:01.950Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/influxdata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-04-28T20:09:23.000Z","updated_at":"2025-02-26T13:46:26.000Z","dependencies_parsed_at":"2023-05-31T20:45:41.953Z","dependency_job_id":null,"html_url":"https://github.com/influxdata/iot-api-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Fiot-api-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Fiot-api-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Fiot-api-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/influxdata%2Fiot-api-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/influxdata","download_url":"https://codeload.github.com/influxdata/iot-api-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248325295,"owners_count":21084902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T11:19:21.711Z","updated_at":"2025-04-11T01:32:31.645Z","avatar_url":"https://github.com/influxdata.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iot-api-python\n\nThis example project provides a Python REST API server that interacts with the InfluxDB v2 HTTP API.\nThe project uses the [Flask](https://palletsprojects.com/p/flask/) framework and the [InfluxDB v2 API client library for Python](https://docs.influxdata.com/influxdb/v2/api-guide/client-libraries/python/) to demonstrate how to build an app that collects, stores, and queries IoT device data.\nAfter you have set up and run your `iot-api-python` API server, you can consume the API using the [iot-api-ui](https://github.com/influxdata/iot-api-ui) standalone React frontend.\n\n## Features\n\nThis application demonstrates how you can use InfluxDB client libraries to do the following:\n\n- Create and manage InfluxDB authorizations (API tokens and permissions).\n- Write and query device metadata in InfluxDB.\n- Write and query telemetry data in InfluxDB.\n- Generate data visualizations with the InfluxDB Giraffe library.\n\n## Tutorial and support\n\nTo learn how to build this app from scratch, follow the [InfluxDB v2 OSS tutorial](https://docs.influxdata.com/influxdb/v2/api-guide/tutorials/python/) or [InfluxDB Cloud tutorial](https://docs.influxdata.com/influxdb/cloud/api-guide/tutorials/python/).\nThe app is an adaptation of [InfluxData IoT Center](https://github.com/bonitoo-io/iot-center-v2), simplified to accompany the IoT Starter tutorial.\n\nFor help, refer to the tutorials and InfluxDB documentation or use the following resources:\n\n- [InfluxData Community](https://community.influxdata.com/)\n- [InfluxDB Community Slack](https://influxdata.com/slack)\n\nTo report a problem, submit an issue to this repo or to the [`influxdata/docs-v2` repo](https://github.com/influxdata/docs-v2/issues).\n\n## Get started\n\n### Set up InfluxDB prerequisites\n\nFollow the tutorial instructions to setup your InfluxDB organization, API token, and buckets:\n\n- [Set up InfluxDB OSS v2 prerequisites](https://docs.influxdata.com/influxdb/v2/api-guide/tutorials/python/#set-up-influxdb)\n- [Set up InfluxDB Cloud v2 prerequisites](https://docs.influxdata.com/influxdb/cloud/api-guide/tutorials/python/#set-up-influxdb)\n\nNext, [clone and run the API server](#clone-and-run-the-api-server).\n\n### Clone and run the API server\n\n1. Clone this repository to your machine.\n2. Change to the directory--for example, enter the following command in your terminal:\n\n   ```bash\n   cd ./iot-api-python\n   ```\n\n3. Set environment variables for `INFLUX_TOKEN` and `INFLUX_ORG`--for example, enter the following commands in your terminal:\n\n   ```bash\n   export INFLUX_TOKEN=\u003cINFLUX_TOKEN\u003e\n   export INFLUX_ORG=\u003cINFLUX_ORG_ID\u003e\n   ```\n\n   Replace the following:\n\n   - **`\u003cINFLUX_TOKEN\u003e`**: your InfluxDB [API token](#authorization) with permission to query (_read_) buckets and create (_write_) authorizations for devices.\n   - **`\u003cINFLUX_ORG_ID\u003e`**: your InfluxDB organization ID.\n\n4. If you need to adjust the default URL or bucket names to match your InfluxDB instance, edit the settings in`./config.ini`:\n\n   ```ini\n   [APP]\n   INFLUX_URL = \u003cINFLUX_URL\u003e\n   INFLUX_BUCKET = iot_center\n   INFLUX_BUCKET_AUTH = iot_center_devices\n   ```\n\n   Replace the following:\n\n   - **`\u003cINFLUX_URL\u003e`**: your InfluxDB instance URL--for example, the default OSS URL `http://localhost:8086`.\n\n5. Create and activate a Python virtual environment for the project.\n   Enter the following commands into your terminal:\n\n   ```bash\n   # Create a new virtual environment named \"virtualenv\"\n   # Python 3.8+\n   python -m venv virtualenv\n\n   # Activate the virtualenv (OS X \u0026 Linux)\n   source virtualenv/bin/activate\n   ```\n\n6. Install `pdm` package manager for your system.\nOn Linux or macOS, enter the following command in your terminal:\n\n   ```bash\n   curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -\n   ```\n\n   On Windows, enter the following command in your terminal:\n\n   ```bash\n   (Invoke-WebRequest -Uri https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py -UseBasicParsing).Content | python -\n   ```\n\n7. Use `pdm` to install dependencies.\n   Enter the following command in your terminal:\n\n   ```bash\n   pdm install\n   ```\n\n8. If you use a bash terminal, you can set an environment variable to use dependencies in `pdm.lock` when you run your application scripts--for example, enter the following command in your bash terminal:\n\n   ```bash\n   eval \"$(pdm --pep582)\"\n   ```\n\n9. To start the Flask application, enter the following command in your terminal:\n\n    ```bash\n    flask run -h localhost -p 3001\n    ```\n\n    To view the application, visit \u003chttp://localhost:3001\u003e in your browser.\n\n10. _Optional_: Run the [iot-api-ui](https://github.com/influxdata/iot-api-ui) React frontend to interact with your IoT Starter API server.\n\n## Troubleshoot\n\n### Error: could not find bucket\n\n```json\n{\"error\":\"failed to load data: HttpError: failed to initialize execute state: could not find bucket \\\"iot_center_devices\\\"\"}\n```\n\nSolution: [create buckets](#set-up-influxdb-prerequisites) or adjust the defaults in `config.ini` to match your InfluxDB instance.\n\n## Learn More\n\n### InfluxDB\n\n- Develop with the InfluxDB API for [OSS v2](https://docs.influxdata.com/influxdb/v2/api-guide/) or [Cloud v2](https://docs.influxdata.com/influxdb/cloud/api-guide/).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Fiot-api-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finfluxdata%2Fiot-api-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finfluxdata%2Fiot-api-python/lists"}