Skip to main content

Dune Analytics API

Python 3.9 Code style: black License Build

A simple framework for interacting with Dune Analytics' unsupported API. The primary class (DuneAPI) of this repo is adapted from https://github.com/itzmestar/duneanalytics at commit bdccd5ba543a8f3679e2c81e18cee846af47bc52


Attention ⚠️

This package violates Dune's Terms of Service and will soon be archived/deprecated in favour of Dune's officially supported API. Please visit https://github.com/cowprotocol/dune-client for an analogous API client with similar interface.


Import as Project Dependency

pip install duneapi

Then you should be able to write python scripts similar to the following:

Example Usage

Fill out your Dune credentials in the .env file. The Dune user and password are straight-forward login credentials to Dune Analytics. The DUNE_QUERY_ID is an integer id found in the URL of a query when saved in the Dune interface. This should be created beforehand, but the same query id can be used everywhere throughout the program (as long as it is owned by the account corresponding to the user credentials provided).

You do not have to provide the query id as an environment variable, but doing so, will allow you to use the same id for all fetching needs. For dashboard management, you will need to have a unique id for each query.

Execute Query and Fetch Results from Dune

from duneapi.api import DuneAPI
from duneapi.types import Network, QueryParameter, DuneRecord, DuneQuery
from duneapi.util import open_query


def fetch_records(dune: DuneAPI) -> list[DuneRecord]:
    sample_query = DuneQuery.from_environment(
        raw_sql=open_query("PATH_TO_SOME_SQL_FILE"),
        name="Sample Query",
        network=Network.MAINNET,
        parameters=[
            QueryParameter.number_type("IntParam", 10),
            QueryParameter.text_type("TextParam", "aba"),
        ],
    )
    return dune.fetch(sample_query)


if __name__ == "__main__":
    dune_connection = DuneAPI.new_from_environment()
    records = fetch_records(dune_connection)
    print("First result:", records[0])

Dashboard Management

It will help to get aquainted with the Dashboard configuration file found in ./example/dashboard/my_dashboard.json. This essentially requires filepath and query id to existing dune queries. Generally it is expected that you will use the family of queries contained in an existing dashboard, but there is no actual validation. Technically one could put all queries here and refresh them with this tool.

from duneapi.dashboard import DuneDashboard

dashboard = DuneDashboard("./example/dashboard/_config.json")
dashboard.update()
print("Updated", dashboard)

To fetch some sample ethereum block data, run the sample script as:

python -m example.fetch

This will result in the following console logs:

got 10 records from last query
First record Record(
    string='0x255309e019abaf74bf2d58d4020547c89f875842abae1c874fb0d5ae8eac9859', 
    integer=14362177, 
    decimal=0.14785533, 
    time='2022-03-10T23:50:16+00:00'
)

To fetch your own data follow the code outline in fetch.py

Contributing and Local Development

Clone this Repo and install as follows.

python3 -m venv venv
source ./env/bin/activate
pip install -r requirements.txt
cp .env.sample .env       <----- Copy your Dune credentials here!

Deployment

  1. Bump the version number in setup.py
  2. Build the duneapi package python -m build
  3. Upload to pypi twine upload dist/*

Metadata

Release files for duneapi 8.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for duneapi 8.0.0
File Size Uploaded Provenance Actions
duneapi-8.0.0.tar.gz 35.0 kB Without provenance Details for duneapi-8.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for duneapi 8.0.0
File Interpreter ABI Platform Actions
duneapi-8.0.0-py3-none-any.whl Python 3 none any Details for duneapi-8.0.0-py3-none-any.whl

Total release size: 61.2 kB

Release files / duneapi-8.0.0.tar.gz

Download URL duneapi-8.0.0.tar.gz
Size 35.0 kB
Tags Source
SHA-256 checksum
How to use checksums
855e9b644c74e2f44cff0b31661db419f2375cc2ef417d9cd4541f6643f16d61
BLAKE2b-256 checksum
How to use checksums
84f4106ec25da9df8e0dd23d374d14a543dc64b8c1ee1c9669bc7aff976ac866
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / duneapi-8.0.0-py3-none-any.whl

Download URL duneapi-8.0.0-py3-none-any.whl
Size 26.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b27d93d6bb445625d0ffed881a8f369d621a26fedbd7baa162fc4e7d1d195728
BLAKE2b-256 checksum
How to use checksums
2c29413fee2b750ac4005937dd4cd6c33b6d3d72d83f6cda7514ed25cf8093d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Security for duneapi 8.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

8.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page