InfluxDB 3 Python Client

0.18.0 · active · verified Wed Apr 15

The influxdb3-python library is the community Python client for InfluxDB 3.0 (also known as InfluxDB IOx or InfluxDB Cloud Serverless). It provides a Pythonic interface for writing and querying time-series data using Apache Arrow Flight (gRPC) and InfluxQL/SQL. The current version is 0.18.0, with new releases typically happening monthly or bi-monthly, incorporating new features and bug fixes for integration with InfluxDB 3.0.

Warnings

Install

Imports

Quickstart

Initializes the client, writes a single data point, and then queries data from InfluxDB 3.0. Credentials are sourced from environment variables for secure and flexible deployment. Remember to replace 'YOUR_API_TOKEN' and 'YOUR_DATABASE' or set corresponding environment variables.

import os
from influxdb_client_3 import InfluxDBClient3, Point

# Ensure these environment variables are set or replace with actual values
# Example: export INFLUXDB_V3_HOST="us-east-1-1.aws.cloud2.influxdata.com"
HOST = os.environ.get("INFLUXDB_V3_HOST", "us-east-1-1.aws.cloud2.influxdata.com")
TOKEN = os.environ.get("INFLUXDB_V3_TOKEN", "YOUR_API_TOKEN")
DATABASE = os.environ.get("INFLUXDB_V3_DATABASE", "YOUR_DATABASE")

client = InfluxDBClient3(host=HOST, token=TOKEN, database=DATABASE)

try:
    # Write data
    point = Point("measurement1").tag("tag1", "value1").field("field1", 1.0)
    client.write(point)
    print("Data written successfully.")

    # Query data
    query = f"SELECT * FROM measurement1 WHERE time > now() - interval '1 hour'"
    table = client.query(query=query, database=DATABASE)

    print("\nQuery results:")
    for row in table:
        print(row)

except Exception as e:
    print(f"An error occurred: {e}")
finally:
    client.close()

view raw JSON →