# Exporting influxdb data as csv file in Influx-Python-Client

**URL:** <https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061>\
**Category:** Client SDKs\
**Created:** [August 4, 2021, 9:13pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061 "2021-08-04T21:13:08Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![raginigupta6](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@raginigupta6](https://community.influxdata.com/u/raginigupta6)\
**Post date:** [August 4, 2021, 9:13pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/1 "2021-08-04T21:13:08Z")

</div>

Hi there,

I am using influx 2.0 version and would like to export the data as csv files from the python client library. Any ideas on how I can do that in python?

Thanks  
Ragini

---

<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:** [August 4, 2021, 9:15pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/2 "2021-08-04T21:15:43Z")

</div>

Hello @raginigupta6,  
please check out this:

> **[GitHub - influxdata/influxdb-client-python: InfluxDB 2.0 python client](https://github.com/influxdata/influxdb-client-python#getting-started)**
>
> InfluxDB 2.0 python client. Contribute to influxdata/influxdb-client-python development by creating an account on GitHub.

Specifically the .query\_csv() method.  
Thanks!  
Lmk if you run into any problems and if it works for you, can you share your code example for future community users?  
Thanks!

---

<div class="post-metadata">

**Author:** ![raginigupta6](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@raginigupta6](https://community.influxdata.com/u/raginigupta6)\
**Post date:** [August 4, 2021, 9:38pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/3 "2021-08-04T21:38:20Z")

</div>

Thank youu. I tried the following function but it’s not supported by the py client library:

```auto
client = influxdb.InfluxDBClient( .. )
points = client.query(query, chunked=True, chunk_size=10000).get_points()
dfs = pd.DataFrame(points)
...
for d in dfs:
    d.to_csv(filename, sep="\t")

```

---

<div class="post-metadata">

**Author:** ![raginigupta6](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@raginigupta6](https://community.influxdata.com/u/raginigupta6)\
**Post date:** [August 4, 2021, 9:40pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/4 "2021-08-04T21:40:50Z")

</div>

Hi there,

I tried the query\_csv() method (as mentioned here [GitHub - influxdata/influxdb-client-python: InfluxDB 2.0 python client](https://github.com/influxdata/influxdb-client-python#getting-started)) but the client library does not support it either. Getting this error:

`AttributeError: 'function' object has no attribute 'query_csv'`

---

<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:** [August 4, 2021, 9:46pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/5 "2021-08-04T21:46:46Z")

</div>

Hello @raginigupta6,  
Silly question, but can you please share the code you tried? I just want to double check for a small typo anywhere.  
Thank you.

---

<div class="post-metadata">

**Author:** ![raginigupta6](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@raginigupta6](https://community.influxdata.com/u/raginigupta6)\
**Post date:** [August 4, 2021, 9:59pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/6 "2021-08-04T21:59:55Z")

</div>

Sure,

here it is:

```auto
from influxdb_client import InfluxDBClient, Point, WritePrecision
from datetime import datetime
from influxdb_client import InfluxDBClient, Point, WritePrecision
token = "Jxxxxxxxxxx"
org = "xxxx"
bucket = "txxx"
client = InfluxDBClient(url="http://xx.xx.xx.xx:8086", token=token)
query = ''' from(bucket: "timeseriesDB") |> range(start: -10m) |> filter(fn:(r) => r._measurement == "go_info") '''

csv_result = client.query_api.query_csv('from(bucket:"timeseriesDB") |> range(start: -1d)')
val_count = 0
for row in csv_result:
    for cell in row:
        val_count += 1
        print("value returned",cell)

```

```auto
Error:
AttributeError: 'function' object has no attribute 'query_csv'

```

---

<div class="post-metadata">

**Author:** ![raginigupta6](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@raginigupta6](https://community.influxdata.com/u/raginigupta6)\
**Post date:** [August 4, 2021, 10:51pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/7 "2021-08-04T22:51:09Z")

</div>

Nevermind, the query\_csv function works now.

Turns out that I had to correctly install the influxdb-client[ciso] package with Visual C++ build tools instead of just influxdb-client.

Also, I wanted to know if there is a limit on how much data it can fetch at a time?

Thanks again for your prompt response 🙂

---

<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:** [August 5, 2021, 2:55pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/8 "2021-08-05T14:55:37Z")

</div>

Hello @raginigupta6,  
Im happy it’s working.  
@bednar might know about query limits–thanks!!!  
But heres a blog that @raginigupta6 you might find interesting based off of @bednar’s work:

> **[Write Millions of Points From CSV to InfluxDB with 2.0 Python Client](https://www.influxdata.com/blog/write-millions-of-points-from-csv-to-influxdb-with-the-2-0-python-client/)**
>
> Today we will learn how you can write millions of points to InfluxDB 2.0 with the InfluxDB Python Client on your local machine in a matter of seconds. The inspiration for this blog and this exercise comes from Mark Litwintschiks Benchmark.

Thanks!!

---

<div class="post-metadata">

**Author:** ![bednar](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/bednar/32/3690_2.png) [@bednar](https://community.influxdata.com/u/bednar)\
**Post date:** [August 6, 2021, 5:08am UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/9 "2021-08-06T05:08:16Z")

</div>

@raginigupta6, the `query_csv` should perform very well because the response is directly streamed into `csv_reader`

---

<div class="post-metadata">

**Author:** ![koenwindey](https://sea1.discourse-cdn.com/flex023/user_avatar/community.influxdata.com/koenwindey/32/5382_2.png) [@koenwindey](https://community.influxdata.com/u/koenwindey)\
**Post date:** [August 22, 2021, 3:29pm UTC](https://community.influxdata.com/t/exporting-influxdb-data-as-csv-file-in-influx-python-client/21061/10 "2021-08-22T15:29:47Z")

</div>

Thanks guys, I was looking for something like this.

I ended up also writing to a csv file:

```auto
# get query as csv
csv_result = query_api.query_csv(query=myQuery, org=myOrg)
#write to csv
csv_file = open(r'C:\temp\python\output.csv', "w",newline='')
writer = csv.writer(csv_file)
for row in csv_result:
     writer.writerow(row)
csv_file.close()

```
