Skip to main content
We currently support a Python SDK for working with our API. You’ll find Python SDK snippets on all endpoint pages. If you want to go deeper into the code, check out these files.

Installation

To install the SDK, run the following command in your terminal:
pip install dune-client
Be sure you are using the latest release. You can find all release versions here - there may be code added to the repo that has not been put into a release yet.

Quick Start

Initialize the client with your API key:
from dune_client.client import DuneClient

# Initialize client
dune = DuneClient(api_key="YOUR_API_KEY")

Working with Queries

You will commonly work with the QueryBase class which can be created like this:
from dune_client.query import QueryBase
from dune_client.types import QueryParameter

query = QueryBase(
    name="Sample Query",
    query_id=1215383,
    params=[
        QueryParameter.text_type(name="TextField", value="Word"),
        QueryParameter.number_type(name="NumberField", value=3.1415926535),
        QueryParameter.date_type(name="DateField", value="2022-05-04 00:00:00"),
        QueryParameter.enum_type(name="EnumField", value="Option 1"),
    ],
)
print("Results available at", query.url())
The query object is defined as QueryBase and all properties can be found in this file.

Executing Queries

Execute a query and get results:
from dune_client.client import DuneClient
from dune_client.query import QueryBase

dune = DuneClient(api_key="YOUR_API_KEY")

query = QueryBase(
    name="Sample Query",
    query_id=1215383,
)

# Execute the query
results = dune.run_query(query)

Working with Results

Other classes such as execution results can be found here, detailing operations like ResultsResponse.get_rows() for getting the data out of a GET request.

Using Pandas DataFrames

If you are trying to load data into a Pandas DataFrame, you can use the following function from the SDK:
# Get results as a DataFrame
results_df = dune.run_query_dataframe(query)

Additional Resources