Giter VIP home page Giter VIP logo

influx-api-python's Introduction

Create a sample Python application

This example project provides a Python server-side REST API that interacts with InfluxDB. It is an adaptation of InfluxData IoT Center, simplified to accompany the InfluxData IoT Starter tutorial. You can consume this API with the example iot-api-ui React frontend. The project uses the Flask framework and the InfluxDB API client library for Python.

Features

This application demonstrates how you can use InfluxDB client libraries to do the following:

  • Create and manage InfluxDB authorizations (API tokens and permissions).
  • Write and query device metadata in InfluxDB.
  • Write and query telemetry data in InfluxDB.
  • Generate data visualizations with the InfluxDB Giraffe library.

Get started

To learn how to create the app from scratch, follow the IoT Starter tutorial. To run the app, do the following:

  1. If you haven't already, create an InfluxDB Cloud account or install InfluxDB OSS.

  2. Clone this repository to your machine.

  3. Change to the directory--for example, enter the following code into the terminal:

    cd ./iot-api-python
  4. Set environment variables for INFLUX_TOKEN and INFLUX_ORG--for example, enter the following commands into your terminal:

    export INFLUX_TOKEN=<INFLUX_TOKEN>
    export INFLUX_ORG=<INFLUX_ORG_ID>

    Replace the following:

    • <INFLUX_TOKEN>: your InfluxDB API token with permission to query (read) buckets and create (write) authorizations for devices.
    • <INFLUX_ORG_ID>: your InfluxDB organization ID.
  5. If you need to adjust the defaults to match your InfluxDB instance, edit the settings in./config.ini:

    [APP]
    INFLUX_URL = <INFLUX_URL>
    INFLUX_BUCKET = iot_center
    INFLUX_BUCKET_AUTH = iot_center_devices

    Replace the following:

    • <INFLUX_URL>: your InfluxDB instance URL--for example, the default OSS URL http://localhost:8086.
  6. Create and activate a Python virtual environment for the project. Enter the following commands into your terminal:

    # Create a new virtual environment named "virtualenv"
    # Python 3.8+
    python -m venv virtualenv
    
    # Activate the virtualenv (OS X & Linux)
    source virtualenv/bin/activate
  7. Install pdm package manager for your system. On Linux or macOS, enter the following command into your terminal:

    curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3 -

    On Windows, enter the following command into your terminal:

    (Invoke-WebRequest -Uri https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py -UseBasicParsing).Content | python -
  8. Use pdm to install dependencies. Enter the following command into your terminal:

    pdm install
  9. If you use a bash terminal, you can set an environment variable to use dependencies in pdm.lock when you run your application scripts. Enter the following command into your bash terminal:

    eval "$(pdm --pep582)"
  10. To start the Flask application, enter the following command into your terminal:

    flask run -h localhost -p 3001

    To view the application, visit http://localhost:3001 in your browser.

  11. Next, you can use the example iot-api-ui React frontend to interact with the API.

influx-api-python's People

Contributors

jstirnaman avatar sunbryely-influxdata avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.