This guide provides a step-by-step process on exporting data from Dune, either through CSV downloads or the API.

Export Methods and File Formats

You can export data from Dune using two primary methods. Each offers different capabilities and file formats:

  • CSV Downloads: Ideal for static data exports, CSV downloads allow you to save query results in a spreadsheet-compatible format. You can easily open these files in spreadsheet software like Microsoft Excel or Google Sheets.
  • API Exports: API exports offer more flexibility and customization options. You can retrieve data in JSON or CSV formats, making it suitable for integration with third-party tools or custom analytics platforms.

Understanding Credit Usage for Data Export

Before you start exporting data from Dune, it’s essential to understand how credits are consumed during the export process. Each export action, whether through CSV downloads or the API, deducts credits from your account based on the amount of data and the method used.

For a comprehensive overview of how credits work in Dune, please refer to our detailed guide on the credit system

Costs for Exporting Data:

  • CSV Exports: Available only to users on Plus and Premium plans. Each CSV file download will deduct credits depending on the size and complexity of the data extracted:
    • Plus Plan: 5,000 data points per credit
    • Premium Plan: 25,000 data points per credit
  • API Exports: Available across all plans, but with varying rate limits and credit costs:
    • Free Plan: 1,000 data points per credit
    • Plus Plan: 5,000 data points per credit
    • Premium Plan: 25,000 data points per credit

For more details on each plan, visit our pricing page.

Rate Limits:

Rate limits determine how frequently you can initiate data exports and at what volume. For detailed information on adjusting your export activities to stay within these limits while managing your credits efficiently, refer to our API rate limits guide.

Identify the Dataset for Export

Begin by pinpointing the dataset or query result you wish to export. For instance, given the recent buzz around Friend.Tech, you might want to export the results from this query: https://dune.com/queries/2945343.

Export via CSV

  • Navigate to the query interface.
  • Simply click the “Export to CSV” button.

Export via API

Ensure you have an API key. If not, generate one:

  1. Navigate to: SettingsAPI.
  2. Click on “Create new API key”.
  3. Remember to copy the entire API key before confirming.

For this guide, we’ll focus on exporting data using the ‘get latest query result’ endpoint. Here’s a Python example:

First, create a .env file with the API key you just created.

DUNE_API_KEY= <insert your key>

import dotenv
import os
import json
import requests
import pandas as pd

def get_latest_query_result(query_id):
    res_df = pd.DataFrame()
    try:
        result_url = f"https://api.dune.com/api-referencev1/query/{query_id}/results"
        result_response = requests.get(result_url, headers=headers)
        print(json.loads(result_response.text))
        query_res = json.loads(result_response.text)["result"]["rows"]
        res_df = pd.DataFrame.from_dict(query_res)
    except Exception as e:
        print(f"Error retrieving result for query {query_id}: {e}")
    return res_df

dotenv.load_dotenv('path_to_env_file')  # Replace 'path_to_env_file' with your .env file path
api_key = os.getenv("DUNE_API_KEY")
query_id = 2945343
headers = {"x-dune-api-key": api_key}
latest_res = get_latest_query_result(query_id)
print(latest_res)

There are multiple methods to export data via the API, and it’s possible to get data in various formats like JSON and CSV. You can even integrate the data with Google Sheets. For a comprehensive guide, refer to this page.

Access the ‘get latest result’ endpoint directly from the Dune UI. When viewing a query, click the API icon in the top-right corner and copy the endpoint URL.