---
title: Python Flight client
description: The Python Flight client integrates with Python scripts and applications to query data stored in InfluxDB.
url: https://docs.influxdata.com/influxdb3/enterprise/reference/client-libraries/flight/python-flight/
estimated_tokens: 3448
product: InfluxDB 3 Enterprise
version: enterprise
---

# Python Flight client

[Apache Arrow Python bindings](https://arrow.apache.org/docs/python/index.html) 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](/influxdb3/enterprise/reference/client-libraries/v3/python/) for integrating InfluxDB 3 with your Python application code.

[InfluxDB 3 client libraries](/influxdb3/enterprise/reference/client-libraries/v3/) wrap Apache Arrow Flight clients and provide convenient methods for [writing](/influxdb3/enterprise/write-data/api-client-libraries/), [querying](/influxdb3/enterprise/query-data/execute-queries/), and processing data stored in InfluxDB 3 Enterprise. 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 3 Enterprise database:

<!-- Tabbed content: Select one of the following options -->

**SQL:**

```python
# 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://localhost:8181: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())
```

**InfluxQL:**

```python
# 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://localhost:8181: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())
```

<!-- End tabbed content -->

Replace the following:

-   `DATABASE_NAME`: your InfluxDB 3 Enterprise database
-   `DATABASE_TOKEN`: a [database token](/influxdb3/enterprise/admin/tokens/database/) with sufficient permissions to the specified database

[Flight client](/influxdb3/enterprise/tags/flight-client/) [Python](/influxdb3/enterprise/tags/python/) [gRPC](/influxdb3/enterprise/tags/grpc/) [SQL](/influxdb3/enterprise/tags/sql/) [Flight SQL](/influxdb3/enterprise/tags/flight-sql/) [client libraries](/influxdb3/enterprise/tags/client-libraries/)
