Simple python client for exctracting data from the Dune Analytics API
Project description
spice 🌶️
Simple python client for extracting data from the Dune Analytics API
Goals of spice
:
- simple, no OOP, entire api is just one function
- support both sync and async workflows
- tight integration with polars
To discuss spice
, head to the Paradigm Data Tools Telegram channel.
Table of Contents
Installation
pip install dune_spice
Examples
Can either use the sync workflow or async workflow. Each workflow has only one function.
See API Reference below for the full list of query function arguments.
Sync Workflow
import spice
# get most recent query results using query id
df = spice.query(21693)
# get most recent query results using query url
df = spice.query('https://dune.com/queries/21693')
# perform new query execution and get results
df = spice.query(query, refresh=True)
# get query results for input parameters
df = spice.query(query, parameters={'network': 'ethereum'})
# perform new query execution, but do not wait for result
execution = spice.query(query, poll=False)
# get results of previous execution
df = spice.query(execution)
Async Workflow
The async API is identical to the sync API as above, just add async_
prefix.
df = await spice.async_query(21693)
df = await spice.async_query('https://dune.com/queries/21693')
df = await spice.async_query(query, refresh=True)
df = await spice.async_query(query, parameters={'network': 'ethereum'})
execution = await spice.async_query(query, poll=False)
df = await spice.async_query(execution)
API Reference
Types
from typing import Any, Literal, Mapping, Sequence, TypedDict
import polars as pl
# query is an int id or query url
Query = int | str
# execution performance level
Performance = Literal['medium', 'large']
# execution
class Execution(TypedDict):
execution_id: str
Functions
These functions are accessed as spice.query()
and spice.aysnc_query()
.
def query(
query_or_execution: Query | Execution,
*,
verbose: bool = True,
refresh: bool = False,
parameters: Mapping[str, Any] | None = None,
api_key: str | None = None,
performance: Performance = 'medium',
poll: bool = True,
poll_interval: float = 1.0,
limit: int | None = None,
offset: int | None = None,
sample_count: int | None = None,
sort_by: str | None = None,
columns: Sequence[str] | None = None,
extras: Mapping[str, Any] | None = None,
dtypes: Sequence[pl.DataType] | None = None,
) -> pl.DataFrame | Execution:
"""get results of query as dataframe
# Parameters
- query_or_execution: query or execution to retrieve results of
- verbose: whether to print verbose info
- refresh: trigger a new execution, or just use most recent execution
- parameters: dict of query parameters
- api_key: dune api key, otherwise use DUNE_API_KEY env var
- performance: performance level
- poll: wait for result as DataFrame, or just return Execution handle
- poll_interval: polling interval in seconds
- limit: number of rows to query in result
- offset: row number to start returning results from
- sample_count: number of random samples from query to return
- sort_by: an ORDER BY clause to sort data by
- columns: columns to retrieve, by default retrieve all columns
- extras: extra parameters used for fetching execution result
- examples: ignore_max_datapoints_per_request, allow_partial_results
- dtypes: dtypes to use in output polars dataframe
"""
...
async def async_query(
# all the same parameters as query()
...
) -> pl.DataFrame | Execution:
"""get results of query as dataframe, asynchronously
## Parameters
[see query()]
"""
...
FAQ
How do I set my Dune API key?
spice
looks for a Dune api key in the DUNE_API_KEY
environment variable.
Which endpoints does this package support?
spice
interacts only with Dune's SQL-related API endpoints, documented here.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file dune_spice-0.1.2.tar.gz
.
File metadata
- Download URL: dune_spice-0.1.2.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f075be76211baf3e63393684b5b5e13f8032531974457c2e5c2b1f23f2cc88a |
|
MD5 | 5df92950ba59078c89010a0b9d4be3b2 |
|
BLAKE2b-256 | b70625a4a69c2b70bba60070eb8acfa2d53dc0f188f31387cc558e18fe61c84e |
File details
Details for the file dune_spice-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: dune_spice-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.31.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed89431b156a73227638e8fa7c1762d0e0f26cfa1ccbce7657a24b91bd7dacf0 |
|
MD5 | 741a7121d469ce6b9084e449a604dd5b |
|
BLAKE2b-256 | 400e6fee7abb99efca988af5649ba57d88347cb4cd271665035008e3ba5a85b3 |