Documentation

Python Flight client

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

Use InfluxDB 3 client libraries

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

InfluxDB 3 client libraries wrap Apache Arrow Flight clients and provide convenient methods for writing, querying, and processing data stored in InfluxDB Cloud Serverless. 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 Cloud Serverless bucket:

# 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,
      '1970-01-01T00:00:00Z') 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": "
BUCKET_NAME
"
,
"sql_query": sql, "query_type": "sql" })) token = (b"authorization", bytes(f"Bearer
API_TOKEN
"
.encode('utf-8')))
options = FlightCallOptions(headers=[token]) client = FlightClient(f"grpc+tls://cloud2.influxdata.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())
  • Copy
  • Fill window
# 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": "
BUCKET_NAME
"
,
"sql_query": influxql, "query_type": "influxql" })) token = (b"authorization", bytes(f"Bearer
API_TOKEN
"
.encode('utf-8')))
options = FlightCallOptions(headers=[token]) client = FlightClient(f"grpc+tls://cloud2.influxdata.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())
  • Copy
  • Fill window

Replace the following:

  • BUCKET_NAME: your InfluxDB Cloud Serverless bucket
  • API_TOKEN: a token with sufficient permissions to the bucket

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:

InfluxDB Cloud Serverless