Skip to main content
Use the published Python SDK to run queries and fetch their results. Some endpoint pages also include Python SDK snippets. See the SDK source for additional methods.

Installation

To install the SDK, run the following command in your terminal:
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:

Working with Queries

You will commonly work with the QueryBase class which can be created like this:
The query object is defined as QueryBase and all properties can be found in this file.

Executing Queries

Execute a query and get results:
To run SQL directly, call dune.run_sql(query_sql="SELECT 1 AS value"). Both methods wait for completion and return ResultsResponse. The older execute(query) method only submits an execution; it does not fetch result rows. For query parameters, pass QueryBase(query_id=..., params=[QueryParameter.text_type(name="blockchain", value="ethereum")]) to run_query.

Working with Results

Read rows with results.get_rows() or results.result.rows when a result is present. The SDK’s high-level run_query method retrieves all pages. See the response models. dune.get_latest_result(query_id, max_age_hours=8) may rerun a query when its saved result is older than eight hours. A rerun consumes execution credits.

Using Pandas DataFrames

If you are trying to load data into a Pandas DataFrame, you can use the following function from the SDK:

Additional Resources

GitHub Repository

View source code, examples, and full documentation

API Files

Explore the API implementation

Releases

Check the latest release versions

Report Issues

Report bugs or request features