Documentation

Python client library

This page documents an earlier version of InfluxDB OSS. InfluxDB 3 Core is the latest stable version.

API token hashing is enabled by default in InfluxDB OSS 2.9.0

Stronger token security: tokens are stored as hashes on disk, so a copy of the database file doesn’t expose usable tokens. Existing tokens are hashed on first startup and the original strings can’t be recovered afterward — capture any plaintext tokens you still need before you upgrade.

For more information, see Token hashing.

Use the InfluxDB Python client library to integrate InfluxDB into Python scripts and applications.

This guide presumes some familiarity with Python and InfluxDB. If just getting started, see Get started with InfluxDB.

Before you begin

  1. Install the InfluxDB Python library:

    pip install influxdb-client
  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. For example: https://us-west-2-1.aws.cloud2.influxdata.com.)

Write data to InfluxDB with Python

We are going to write some data in line protocol using the Python library.

  1. In your Python program, import the InfluxDB client library and use it to write data to InfluxDB.

    import influxdb_client
    from influxdb_client.client.write_api import SYNCHRONOUS
  2. Define a few variables with the name of your bucket, organization, and token.

    bucket = "<my-bucket>"
    org = "<my-org>"
    token = "<my-token>"
    # Store the URL of your InfluxDB instance
    url="http://localhost:8086"
  3. Instantiate the client. The InfluxDBClient object takes three named parameters: url, org, and token. Pass in the named parameters.

    client = influxdb_client.InfluxDBClient(
       url=url,
       token=token,
       org=org
    )

    The InfluxDBClient object has a write_api method used for configuration.

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

    write_api = client.write_api(write_options=SYNCHRONOUS)
  5. Create a point object and write it to InfluxDB using the write method of the API writer object. The write method requires three parameters: bucket, org, and record.

    p = influxdb_client.Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
    write_api.write(bucket=bucket, org=org, record=p)

Complete example write script

import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS

bucket = "<my-bucket>"
org = "<my-org>"
token = "<my-token>"
# Store the URL of your InfluxDB instance
url="http://localhost:8086"

client = influxdb_client.InfluxDBClient(
    url=url,
    token=token,
    org=org
)

# Write script
write_api = client.write_api(write_options=SYNCHRONOUS)

p = influxdb_client.Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
write_api.write(bucket=bucket, org=org, record=p)

Query data from InfluxDB with Python

  1. Instantiate the query client.

    query_api = client.query_api()
  2. Create a Flux query, and then format it as a Python string.

    query = 'from(bucket:"my-bucket")\
    |> range(start: -10m)\
    |> filter(fn:(r) => r._measurement == "my_measurement")\
    |> filter(fn:(r) => r.location == "Prague")\
    |> filter(fn:(r) => r._field == "temperature")'

    The query client sends the Flux query to InfluxDB and returns a Flux object with a table structure.

  3. Pass the query() method two named parameters:org and query.

    result = query_api.query(org=org, query=query)
  4. Iterate through the tables and records in the Flux object.

    • Use the get_value() method to return values.
    • Use the get_field() method to return fields.
    results = []
    for table in result:
      for record in table.records:
        results.append((record.get_field(), record.get_value()))
    
    print(results)
    [(temperature, 25.3)]

The Flux object provides the following methods for accessing your data:

  • get_measurement(): Returns the measurement name of the record.
  • get_field(): Returns the field name.
  • get_value(): Returns the actual field value.
  • values: Returns a map of column values.
  • values.get("<your tag>"): Returns a value from the record for given column.
  • get_time(): Returns the time of the record.
  • get_start(): Returns the inclusive lower time bound of all records in the current table.
  • get_stop(): Returns the exclusive upper time bound of all records in the current table.

Complete example query script

import influxdb_client
from influxdb_client.client.write_api import SYNCHRONOUS

bucket = "<my-bucket>"
org = "<my-org>"
token = "<my-token>"
# Store the URL of your InfluxDB instance
url="http://localhost:8086"

client = influxdb_client.InfluxDBClient(
    url=url,
    token=token,
    org=org
)

# Query script
query_api = client.query_api()
query = 'from(bucket:"my-bucket")\
|> range(start: -10m)\
|> filter(fn:(r) => r._measurement == "my_measurement")\
|> filter(fn:(r) => r.location == "Prague")\
|> filter(fn:(r) => r._field == "temperature")'
result = query_api.query(org=org, query=query)
results = []
for table in result:
    for record in table.records:
        results.append((record.get_field(), record.get_value()))

print(results)
[(temperature, 25.3)]

For more information, see the Python client README on GitHub.


Was this page helpful?

Thank you for your feedback!


InfluxDB OSS 2.9.0: API tokens are hashed by default

Stronger token security in InfluxDB OSS 2.9.0 — tokens are hashed on disk by default. Existing tokens are hashed on first startup and can’t be recovered afterward. Capture any plaintext tokens you still need before you upgrade.

View InfluxDB OSS 2.9.0 release notes

Hashed tokens authenticate exactly like unhashed tokens — clients and integrations keep working.

Also new in 2.9.0:

  • Configurable backup compression
  • Restore support for backups containing hashed tokens
  • Tighter Edge Data Replication queue validation
  • Flux upgrade
  • Compaction reliability improvements

Key enhancements in Explorer 1.9

Explorer 1.9 is now available with InfluxQL support, an AI-assisted Flux to SQL converter (beta), and new live sample data simulators.

View Explorer 1.9 release notes

Explorer 1.9 includes new features and improvements that make it easier to query, visualize, and manage data.

Highlights:

  • Flux to SQL converter (beta): Convert Flux queries to SQL with an AI-assisted converter.
  • InfluxQL support: Query data with InfluxQL in the Data Explorer and dashboards, and save and load InfluxQL queries.
  • InfluxQL visualizations: Render line and bar charts from InfluxQL results with per-tag series grouping.
  • Query error history: Review a history of query errors in the query tool.
  • Live sample data simulators: Generate continuous live sample data with new bird data and signal generator simulators.

For more details, see Explorer 1.9 release notes

InfluxDB 3.10 is now available

InfluxDB 3 Core 3.10 adds an automatic catalog format upgrade, a configurable query-concurrency limit, and processing engine improvements.

Key updates in InfluxDB 3 Core 3.10:

  • Catalog format upgrade: the on-disk catalog automatically upgrades from format v2 to v3 on first 3.10 startup. Migration is one-way—back up your catalog before upgrading.
  • --max-concurrent-queries: limit concurrent queries (adjustable at runtime).
  • GET /ready endpoint for readiness probes.
  • Processing engine: cross-database queries and trigger lockdown flags.

For more information, see the InfluxDB 3 Core release notes.

InfluxDB 3.10 is now available

InfluxDB 3 Enterprise 3.10 adds automated backup and restore, row-level deletions, and user management, with an automatic catalog format upgrade and performance preview improvements.

Key updates in InfluxDB 3 Enterprise 3.10:

  • Catalog format upgrade: the on-disk catalog automatically upgrades from format v2 to v3 on first 3.10 startup. Migration is one-way—back up your catalog before upgrading.
  • Automated backup and restore (beta)
  • Row-level deletions
  • User management (authentication and RBAC) — preview
  • Performance preview improvements

Backup and restore, row-level deletions, and the performance preview require the Enterprise storage engine upgrade (opt-in beta). Beta and preview features are subject to breaking changes and aren’t recommended for production use.

For more information, see the InfluxDB 3 Enterprise release notes

Telegraf Enterprise is now generally available

Telegraf Enterprise is now generally available, along with Telegraf Controller v1.0.

Telegraf Enterprise combines Telegraf Controller, a centralized management console for Telegraf, with official support from InfluxData. Manage configurations, monitor fleet health, and operate tens of thousands of Telegraf agents from a single system.

InfluxDB Docker latest tag changing to InfluxDB 3 Core

On September 15, 2026, the latest tag for InfluxDB Docker images will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments.

If using Docker to install and run InfluxDB, the latest tag will point to InfluxDB 3 Core. To avoid unexpected upgrades, use specific version tags in your Docker deployments. For example, if using Docker to run InfluxDB v2, replace the latest version tag with a specific version tag in your Docker pull command–for example:

docker pull influxdb:2