Documentation

InfluxDB client libraries

InfluxDB client libraries are language-specific packages that integrate with InfluxDB APIs and support InfluxDB 1.8+ and InfluxDB 2.x.

Client libraries for InfluxDB 1.7 and earlier may continue to work, but aren’t maintained by InfluxData.

Client libraries for InfluxDB 2.x and 1.8+

InfluxDB 2.x client libraries use InfluxDB /api/v2 endpoints and work with InfluxDB 2.0 API compatibility endpoints. Functionality varies among client libraries. For specifics about a client library, see the library’s GitHub repository.

Arduino

C#

C++

Go

Java

JavaScript

PHP

Python

Ruby

Install and use a client library

To install and use the Python client library, follow the instructions below. To install and use other client libraries, refer to the client library documentation for detail.

Install and use the Python client library

  1. Install the Python client library.

    pip install influxdb-client
    
    • Copy
    • Fill window
  2. Ensure that InfluxDB is running. If running InfluxDB locally, visit http://localhost:8086. (If using InfluxDB Cloud, visit the URL of your InfluxDB Cloud UI.)

  3. In your program, import the client library and use it to write data to InfluxDB. For example:

    import influxdb_client
    from influxdb_client.client.write_api import SYNCHRONOUS
    
    • Copy
    • Fill window
  4. Define your database and token variables, and create a client and writer object. The InfluxDBClient object takes 2 parameters: url and token

    database = "<my-db>"
    token = "<my-token>"
    client = influxdb_client.InfluxDBClient(url="http://localhost:8086",token=token)
    
    • Copy
    • Fill window

    Note: The database (and retention policy, if applicable) are converted to a bucket data store compatible with InfluxDB 2.0.

  5. Instantiate a writer object using the client object and the write_api method. Use the write_api method to configure the writer object.

    client = influxdb_client.InfluxDBClient(url=url, token=token)
    write_api = client.write_api(write_options=SYNCHRONOUS)
    
    • Copy
    • Fill window
  6. Create a point object and write it to InfluxDB using the write method of the API writer object. The write method requires three parameters: database, (optional) retention policy, and record.

    p = influxdb_client.Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
    write_api.write(database:rp, record=p)
    
    • Copy
    • Fill window

Was this page helpful?

Thank you for your feedback!


The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Read more

InfluxDB 3 Core and Enterprise are now in Beta

InfluxDB 3 Core and Enterprise are now available for beta testing, available under MIT or Apache 2 license.

InfluxDB 3 Core is a high-speed, recent-data engine that collects and processes data in real-time, while persisting it to local disk or object storage. InfluxDB 3 Enterprise is a commercial product that builds on Core’s foundation, adding high availability, read replicas, enhanced security, and data compaction for faster queries. A free tier of InfluxDB 3 Enterprise will also be available for at-home, non-commercial use for hobbyists to get the full historical time series database set of capabilities.

For more information, check out: