/duneanalytics

Unofficial Python Library for Dune Analytics

Primary LanguagePythonApache License 2.0Apache-2.0

Dune Analytics

Python 3.9

License

Build


Unofficial Python Library for Dune Analytics

The library can be used to fetch the table data from python backend.

Disclaimer: Use at your own risk!

It may not work for some/all urls.

This library doesn't run the query, rather it fetches the query result from the backend.


Charts Plotted:

Here are some examples of charts plotted in Googlesheet after fetching the data.


@balancerlabs / Balancer New/Old Traders

Balancer


@k06a / 1inch New/Old Users Per Day

1inch


@Bancor / Bancor Unique Protected Wallets Over Time

Bancor


Installation:

use pip to install:

pip install duneanalytics

Authentication:

You need to have username & password for Dune Analytics


Example usage:

from duneanalytics import DuneAnalytics

Initialize client and login

dune = DuneAnalytics('username', 'password', 'ACCESS_ID', 'SECRET_KEY')
# try to login
dune.login()
# fetch token
dune.fetch_auth_token()

# fetch query result id using query id
# query id for any query can be found from the url of the query:
# for example: 
# https://dune.com/queries/4494/8769 => 4494
# https://dune.com/queries/3705/7192 => 3705
# https://dune.com/queries/3751/7276 => 3751

result_id = dune.query_result_id(query_id=5508)

# fetch query result
data = dune.query_result(result_id)

Download and save csv from Dune

# save csv
save_path = './'

# convert json data to csv
dune.query2csv(data, save_path)

# alternative end-to-end csv download with dune pro
dune.download_csv(result_id, save_path)

End-to-end Dune to S3 uploading

result_id = dune.query_result_id(query_id=935947)
dune.dune2space(result_id)

Update permission for all files in s3 space

dune.update_permissions()

Interaction with dydx exchange API

pip install dydx-v3-python

Get asset current price and upload to the s3 space

from duneanalytics import DuneAnalytics

client = DuneAnalytics('username', 'password', 'ACCESS_ID', 'SECRET_KEY')
client.dydx2space('ICP')
# Output: ICP.csv file on s3 with current ICP price