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.
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.
Copy
Ask AI
DUNE_API_KEY= <insert your key>
Copy
Ask AI
import dotenvimport osimport jsonimport requestsimport pandas as pddef 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_dfdotenv.load_dotenv('path_to_env_file') # Replace 'path_to_env_file' with your .env file pathapi_key = os.getenv("DUNE_API_KEY")query_id = 2945343headers = {"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.