# Data query through Python API is slow

**URL:** https://community.influxdata.com/t/data-query-through-python-api-is-slow/30421
**Category:** InfluxDB 2
**Created:** [June 23, 2023, 2:55pm UTC](https://community.influxdata.com/t/data-query-through-python-api-is-slow/30421 "2023-06-23T14:55:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Jason\_LEE](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/jason_lee/32/13702_2.png) [@Jason\_LEE](https://community.influxdata.com/u/Jason_LEE)
#### Post date: [June 23, 2023, 2:55pm UTC](https://community.influxdata.com/t/data-query-through-python-api-is-slow/30421/1 "2023-06-23T14:55:05Z")

</div>

Hello.  
I’m struggling with the slow speed when querying data in FluuxDB.

When querying the same range of data, WebUI takes approximately 100 ms, while Python API takes 6000 ms.

 ![image](https://us1.discourse-cdn.com/flex023/uploads/influxdata/original/2X/d/d07df1b43891ce21db82df2550fa2981aaf018bb.png)

The image above compares the query rate via Python API with the query rate via WebUI.

As you can see, the script used is the same.

I don’t know how to quickly query through API.

I used the same script that is displayed in the UI, but I have no idea why the speed difference occurs.

Please help me.  
Thank you.

python code ====================================================  
import time  
import mysql.connector  
import pickle  
import binascii  
from influxdb\_client import InfluxDBClient, Point, WritePrecision, WriteOptions  
from influxdb\_client.client.write\_api import ASYNCHRONOUS  
import numpy as np  
from datetime import datetime  
import sys  
import random  
from dateutil.parser import parse as parse\_date  
from influxdb\_client.client.query\_api import QueryApi

# InfluxDB settings

influx\_config = {  
‘url’: ‘[http://localhost:8086](http://localhost:8086)’,  
‘token’: ‘n3MAF8LJlj9sofV7IkoZHEcWsMVOMkgN5gQqX7\_JfhuKcRDE0pG6z\_qVxP\_orGITjTo2ekZvLx\_5qRrcKb1fFg==’,  
‘org’: ‘TestORG’,  
‘bucket’: ‘T001’  
}

def read\_influxdb2():  
client = InfluxDBClient(\*\*influx\_config)  
query\_api = client.query\_api()

```
start_time = time.time() # Record start time

query = f'from(bucket: "T001")' \
f'|> range(start: -24h)' \
f'|> filter(fn: (r) => r["_measurement"] == "my_measurement")' \
f'|> aggregateWindow(every: 100ms, fn: mean, createEmpty: false)' \
f'|> yield(name: "mean")'

result = query_api.query(query)    

end_time = time.time() # Record end time
elapsed_time = end_time - start_time # Calculate elapsed time
print(f'Reading took {elapsed_time * 1000} milliseconds')

print(result)

print('@@@@@@@@@ Read Complete @@@@@@@@@')

```

# read\_influxdb2()

---

<div class="post-metadata">

### Author: ![Anaisdg](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/anaisdg/32/6401_2.png) [@Anaisdg](https://community.influxdata.com/u/Anaisdg)
#### Post date: [June 28, 2023, 11:21pm UTC](https://community.influxdata.com/t/data-query-through-python-api-is-slow/30421/2 "2023-06-28T23:21:11Z")

</div>

Hello @Jason_LEE,  
Yes we’re trying to address some of these issues in 3.x with the use or Arrow and Arrow Flight SQL. Unfortunately I don’t think you can expect a fix in 2.x.

> **[Introducing InfluxDB 3.0 | InfluxData](https://www.influxdata.com/products/influxdb-overview/)**
>
> A quantum leap forward for time series databases. InfluxDB 3.0 leverages the cutting-edge InfluxDB IOx engine to put performance front-and-center across an entire product suite.

> **[InfluxDB 3.0: System Architecture | InfluxData](https://www.influxdata.com/blog/influxdb-3-0-system-architecture/)**
>
> This article by Nga Tran, Paul Dix, Andrew Lamb, and Marko Mikulicic describes the system architecture of InfluxDB 3.0 database. #influxdb

> **[Understanding InfluxDB IOx and the Commitment to Open Source | InfluxData](https://www.influxdata.com/blog/understanding-influxdb-iox-commitment-open-source/)**
>
> I wanted to learn more about how the open source components of the new engine help achieve the requirements for the new #InfluxDB engine and why they were chosen. This post covers that precise topic.

> **[Introducing Apache Arrow Flight SQL: Accelerating Database Access](https://arrow.apache.org/blog/2022/02/16/introducing-arrow-flight-sql/)**
>
> This post introduces Arrow Flight SQL, a protocol for interacting with SQL databases over Arrow Flight. We have been working on this protocol over the last six months, and are looking for feedback, interested contributors, and early adopters.
