Documentation

Python Flight client

Apache Arrow Python bindings integrate with Python scripts and applications to query data stored in InfluxDB.

Use InfluxDB v3 client libraries

We recommend using the influxdb3-python Python client library for integrating InfluxDB v3 with your Python application code.

InfluxDB v3 client libraries wrap Apache Arrow Flight clients and provide convenient methods for writing, querying, and processing data stored in InfluxDB Clustered. Client libraries can query using SQL or InfluxQL.

The following examples show how to use the pyarrow.flight and pandas Python modules to query and format data stored in an InfluxDB Clustered database:

# Using pyarrow>=12.0.0 FlightClient
from pyarrow.flight import FlightClient, Ticket, FlightCallOptions 
import json
import pandas
import tabulate

# Downsampling query groups data into 2-hour bins
sql="""
  SELECT DATE_BIN(INTERVAL '2 hours', time) AS time,
    room,
    selector_max(temp, time)['value'] AS 'max temp',
    selector_min(temp, time)['value'] AS 'min temp',
    avg(temp) AS 'average temp'
  FROM home
  GROUP BY
    1,
    room
  ORDER BY room, 1"""
  
flight_ticket = Ticket(json.dumps({
  "namespace_name": "
DATABASE_NAME
"
,
"sql_query": sql, "query_type": "sql" })) token = (b"authorization", bytes(f"Bearer
DATABASE_TOKEN
"
.encode('utf-8')))
options = FlightCallOptions(headers=[token]) client = FlightClient(f"grpc+tls://cluster-host.com:443") reader = client.do_get(flight_ticket, options) arrow_table = reader.read_all() # Use pyarrow and pandas to view and analyze data data_frame = arrow_table.to_pandas() print(data_frame.to_markdown())
# Using pyarrow>=12.0.0 FlightClient
from pyarrow.flight import FlightClient, Ticket, FlightCallOptions 
import json
import pandas
import tabulate

# Downsampling query groups data into 2-hour bins
influxql="""
  SELECT FIRST(temp)
  FROM home 
  WHERE room = 'kitchen'
    AND time >= now() - 100d
    AND time <= now() - 10d
  GROUP BY time(2h)"""
  
flight_ticket = Ticket(json.dumps({
  "namespace_name": "
DATABASE_NAME
"
,
"sql_query": influxql, "query_type": "influxql" })) token = (b"authorization", bytes(f"Bearer
DATABASE_TOKEN
"
.encode('utf-8')))
options = FlightCallOptions(headers=[token]) client = FlightClient(f"grpc+tls://cluster-host.com:443") reader = client.do_get(flight_ticket, options) arrow_table = reader.read_all() # Use pyarrow and pandas to view and analyze data data_frame = arrow_table.to_pandas() print(data_frame.to_markdown())

Replace the following:

  • DATABASE_NAME: your InfluxDB Clustered database
  • DATABASE_TOKEN: a database token with sufficient permissions to the specified database

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 v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered