Skip to main content
In this quickstart, we will walk through how to fetch Dune data in Python.
⌨️ For a quickstart on TypeScript, please download Dune TypeScript SDK and follow this demo project.

Prerequisites

  • Python environment set up (check out uv if you want somewhere to start.)
  • Have a Dune API key from the team/user who’s queries you want to manage (to obtain one follow the steps here)

Step 1: Prepare your Dune query

Have a Dune query you’d like to pull data from. Here, we’ll use this query to get the DAI token balance for vitalik.eth.

Step 2: Install Dune Python SDK

Ensure the Dune Python SDK is installed in your environment. You can install it using pip:

Step 3: Get data from Dune query

Set up a Dune Python client

The API key might either be supplied in the constructor or read through environment variables. The follow env variables might be supplied: DUNE_API_KEY, DUNE_API_BASE_URL, DUNE_API_REQUEST_TIMEOUT.

Get query result

You can fetch a recent saved result or run the query to get fresh data. The Python SDK can rerun a query if the saved result is older than max_age_hours (about three months by default); this consumes execution credits.
  • To paginate query results, please visit the pagination page to get more info.
  • If you are using the Python SDK:
    • For higher level functions like run_query(), pagination is handled for you automatically behind the scene, so you will get the entire dataset as the returned result. You can pass in parameter batch_size to define the maximum number of rows per batch or pagination call.
    • For lower level functions like get_execution_results(), you can pass in pagination parameters limit and offset directly, as instructed here.

Putting it all together