See also: REST intro,
Networks,
Pools
Installation
Copy
# Using pip
pip install dexpaprika-sdk
# Using poetry
poetry add dexpaprika-sdk
# From source
git clone https://github.com/coinpaprika/dexpaprika-sdk-python.git
cd dexpaprika-sdk-python
pip install -e .
Prerequisites
- Python 3.8 or higher
- Connection to the internet to access the DexPaprika API
- No API key required
Quick Example: Get Token Price
Copy
from dexpaprika_sdk import DexPaprikaClient
from dexpaprika_sdk.models import TokenDetails # Type hint example
# Create client and get WETH price on Ethereum
client = DexPaprikaClient()
token: TokenDetails = client.tokens.get_details("ethereum", "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2")
print(f"{token.name}: ${token.price_usd}")
# Output: Wrapped Ether: $3245.67
API Methods Reference
Parameters marked with an asterisk (*) are required.
Show methods
Show methods
client.networks.list()
Endpoint: GET/networks
Gets all supported blockchain networks including Ethereum, Solana, etc.Parameters: NoneReturns: Network IDs, names, and related information. Response Structure.Copy
# Get all networks
networks = client.networks.list()
print(f"Found {len(networks)} networks")
Show methods
Show methods
client.dexes.list_by_network(network_id, page, limit)
Endpoint: GET/networks/{network}/dexes
Gets all DEXes on a specific network.Parameters:network_id
* - ID of the network (e.g., ‘ethereum’, ‘solana’)page
- Page number for pagination (starts at 0)limit
- Number of results per page
Copy
# Get all DEXes on Ethereum
dexes = client.dexes.list_by_network("ethereum")
print(f"Found {len(dexes.dexes)} DEXes on Ethereum")
Show methods
Show methods
client.pools.list(page, limit, sort, order_by)
Endpoint: GET/pools
Gets top pools across all networks with pagination.Parameters:page
- Page number for pagination (starts at 0)limit
- Number of results per pagesort
- Sort direction (‘asc’ or ‘desc’)order_by
- Field to sort by (‘volume_usd’, ‘liquidity_usd’, etc.)
Copy
# Get top 10 pools by volume
top_pools = client.pools.list(limit=10, order_by="volume_usd", sort="desc")
print(f"Top pool: {top_pools.pools[0].dex_name}")
client.pools.list_by_network(network_id, page, limit, sort, order_by)
Endpoint: GET/networks/{network}/pools
Gets pools on a specific network with pagination and sorting options.Parameters:network_id
* - ID of the networkpage
- Page number for pagination (starts at 0)limit
- Number of results per pagesort
- Sort direction (‘asc’ or ‘desc’)order_by
- Field to sort by (‘volume_usd’, ‘liquidity_usd’, etc.)
Copy
# Get top 5 pools on Ethereum by volume
pools = client.pools.list_by_network(
network_id="ethereum",
limit=5,
order_by="volume_usd",
sort="desc"
)
print(f"Found {len(pools.pools)} pools on Ethereum")
client.pools.list_by_dex(network_id, dex_id, page, limit, sort, order_by)
Endpoint: GET/networks/{network}/dexes/{dex}/pools
Gets pools on a specific DEX within a network with pagination.Parameters:network_id
* - ID of the networkdex_id
* - ID of the DEXpage
- Page number for pagination (starts at 0)limit
- Number of results per pagesort
- Sort direction (‘asc’ or ‘desc’)order_by
- Field to sort by (‘volume_usd’, ‘liquidity_usd’, etc.)
Copy
# Get top 10 Uniswap V2 pools on Ethereum
uniswap_pools = client.pools.list_by_dex(
network_id="ethereum",
dex_id="uniswap_v2",
limit=10,
order_by="volume_usd",
sort="desc"
)
print(f"Found {len(uniswap_pools.pools)} Uniswap V2 pools")
client.pools.get_details(network_id, pool_address, inversed)
Endpoint: GET/networks/{network}/pools/{pool_address}
Gets detailed information about a specific pool.Parameters:network_id
* - ID of the networkpool_address
* - On-chain address of the poolinversed
- Whether to invert the price ratio (boolean)
Copy
from dexpaprika_sdk.models import PoolDetails # Type hint example
# Get details for a specific pool (WETH/USDC on Uniswap V2)
pool: PoolDetails = client.pools.get_details(
network_id="ethereum",
pool_address="0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
inversed=False
)
print(f"Pool: {pool.tokens[0].symbol}/{pool.tokens[1].symbol}")
client.pools.get_transactions(network_id, pool_address, page, limit)
Endpoint: GET/networks/{network}/pools/{pool_address}/transactions
Gets transaction history for a specific pool with pagination.Parameters:network_id
* - ID of the networkpool_address
* - On-chain address of the poolpage
- Page number for paginationlimit
- Number of transactions per page
Copy
# Get the latest 20 transactions for a pool
transactions = client.pools.get_transactions(
network_id="ethereum",
pool_address="0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
limit=20
)
from datetime import datetime
latest_tx_time = datetime.fromtimestamp(transactions.transactions[0].block_timestamp).strftime('%Y-%m-%d %H:%M:%S')
print(f"Latest transaction: {latest_tx_time}")
client.pools.get_ohlcv(network_id, pool_address, start, end, limit, interval, inversed)
Endpoint: GET/networks/{network}/pools/{pool_address}/ohlcv
Gets OHLCV (Open, High, Low, Close, Volume) chart data for a pool.Parameters:network_id
* - ID of the networkpool_address
* - On-chain address of the poolstart
* - Start time (ISO date string, YYYY-MM-DD, or Unix timestamp)end
- End time (optional)limit
- Number of data points to returninterval
- Time interval (‘1m’, ‘5m’, ‘15m’, ‘30m’, ‘1h’, ‘6h’, ‘12h’, ‘24h’)inversed
- Whether to invert the price ratio (boolean)
Copy
from datetime import datetime, timedelta
# Get OHLCV data for the past 7 days with 1-hour intervals
end_date = datetime.now()
start_date = end_date - timedelta(days=7)
ohlcv = client.pools.get_ohlcv(
network_id="ethereum",
pool_address="0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
start=start_date.strftime("%Y-%m-%d"),
end=end_date.strftime("%Y-%m-%d"),
interval="1h",
limit=168 # 24 * 7 hours
)
print(f"Received {len(ohlcv)} OHLCV data points")
Show methods
Show methods
client.tokens.get_details(network_id, token_address)
Endpoint: GET/networks/{network}/tokens/{token_address}
Gets comprehensive token information.Parameters:network_id
* - ID of the networktoken_address
* - Token contract address
Copy
# Get WETH token details
weth = client.tokens.get_details(
network_id="ethereum",
token_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
)
print(f"{weth.name} price: ${weth.price_usd}")
client.tokens.get_pools(network_id, token_address, page, limit, sort, order_by, address)
Endpoint: GET/networks/{network}/tokens/{token_address}/pools
Gets pools containing a specific token.Parameters:network_id
* - ID of the networktoken_address
* - Token contract addresspage
- Page number for pagination (starts at 0)limit
- Number of results per pagesort
- Sort direction (‘asc’ or ‘desc’)order_by
- Field to sort by (‘volume_usd’, ‘price_usd’, etc.)address
- Optional second token address to filter for pairs with both tokens
Copy
# Get WETH/USDC pools
pools = client.tokens.get_pools(
network_id="ethereum",
token_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", # WETH
limit=5,
order_by="volume_usd",
sort="desc",
address="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" # USDC
)
for pool in pools.pools:
print(f"{pool.dex_name}: ${pool.volume_usd:,.2f} 24h volume")
Show methods
Show methods
client.search.search(query)
Endpoint: GET/search
Searches across tokens, pools, and DEXes using a query string.Parameters:query
* - Search query string
Copy
# Search for "ethereum" across all entities
results = client.search.search("ethereum")
print(f"Found {len(results.tokens)} tokens")
print(f"Found {len(results.pools)} pools")
print(f"Found {len(results.dexes)} dexes")
Show methods
Show methods
client.utils.get_stats()
Endpoint: GET/stats
Gets platform-wide statistics.Parameters: NoneReturns: Counts of chains, DEXes, pools, and tokens indexed. Response Structure.Copy
# Get platform statistics
stats = client.utils.get_stats()
print(f"Total chains: {stats.chains}")
print(f"Total DEXes: {stats.dexes}")
print(f"Total pools: {stats.pools}")
print(f"Total tokens: {stats.tokens}")
Complete Example
Show example
Show example
Copy
from dexpaprika_sdk import DexPaprikaClient
def main():
# Initialize client
client = DexPaprikaClient()
# Get Ethereum network details
networks = client.networks.list()
ethereum = next((n for n in networks if n.id == "ethereum"), None)
print(f"Found {ethereum.display_name} with {ethereum.dexes_count} DEXes")
# Get WETH token details
weth = client.tokens.get_details(
network_id="ethereum",
token_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
)
print(f"{weth.name} price: ${weth.price_usd}")
# Find WETH/USDC pools
pools = client.tokens.get_pools(
network_id="ethereum",
token_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", # WETH
limit=5,
order_by="volume_usd",
sort="desc",
address="0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" # USDC
)
# Show top pools
print('Top WETH/USDC pools:')
for pool in pools.pools:
print(f"{pool.dex_name}: ${pool.volume_usd:,.2f} 24h volume")
if __name__ == "__main__":
main()
Advanced Features
Error Handling
Show error handling
Show error handling
Copy
from dexpaprika_sdk import DexPaprikaClient
import requests
# Basic error handling
try:
client = DexPaprikaClient()
token = client.tokens.get_details("ethereum", "0xinvalidaddress")
except Exception as e:
if "404" in str(e):
print("Token not found")
elif "429" in str(e):
print("Rate limit exceeded")
else:
print(f"An error occurred: {e}")
# The SDK automatically retries on these status codes:
# 408 (Request Timeout), 429 (Too Many Requests),
# 500, 502, 503, 504 (Server Errors)
# Custom retry configuration
client = DexPaprikaClient(
max_retries=4, # Number of retry attempts (default: 4)
backoff_times=[0.1, 0.5, 1.0, 5.0] # Backoff times in seconds
)
# All API requests will now use these retry settings
try:
networks = client.networks.list()
except requests.exceptions.RetryError as e:
print(f"Failed after multiple retries: {e}")
Caching System
Show caching
Show caching
Copy
from dexpaprika_sdk import DexPaprikaClient
import time
# The SDK includes built-in caching by default
# Demonstration of cache behavior
# Create a regular client with default cache (5 minutes TTL)
client = DexPaprikaClient()
# First call - hits the API
start_time = time.time()
networks = client.networks.list()
first_call_time = time.time() - start_time
print(f"First call (API): {len(networks)} networks, took {first_call_time:.4f}s")
# Second call - served from cache (much faster)
start_time = time.time()
networks = client.networks.list()
second_call_time = time.time() - start_time
print(f"Second call (cached): {len(networks)} networks, took {second_call_time:.4f}s")
print(f"Cache speedup: {first_call_time / second_call_time:.1f}x")
# You can skip the cache when you need fresh data
fresh_networks = client.networks._get("/networks", skip_cache=True)
# Clear the entire cache
client.clear_cache()
# Clear cache only for specific endpoints
client.clear_cache(endpoint_prefix="/networks")
# Different types of data have different cache durations:
# - Network data: 24 hours
# - Pool data: 5 minutes
# - Token data: 10 minutes
# - Statistics: 15 minutes
# - Other data: 5 minutes (default)
Pagination Helper
Show pagination
Show pagination
Copy
from dexpaprika_sdk import DexPaprikaClient
import time
def fetch_all_pools(network_id):
client = DexPaprikaClient()
all_pools = []
page = 0
limit = 50
has_more = True
while has_more:
response = client.pools.list_by_network(
network_id=network_id,
page=page,
limit=limit,
sort="desc",
order_by="volume_usd"
)
all_pools.extend(response.pools)
# Check if there are more pages
has_more = len(response.pools) == limit
page += 1
# Adding a small delay to avoid hitting rate limits
time.sleep(0.1)
print(f"Fetched a total of {len(all_pools)} pools on {network_id}")
return all_pools
# Usage example
ethereum_pools = fetch_all_pools("ethereum")
Parameter Validation
Show validation
Show validation
Copy
from dexpaprika_sdk import DexPaprikaClient
# The SDK automatically validates parameters before making API requests
client = DexPaprikaClient()
# Invalid parameter examples will raise helpful error messages
try:
# Invalid network ID
client.pools.list_by_network(network_id="", limit=5)
except ValueError as e:
print(e) # "network_id is required"
try:
# Invalid sort parameter
client.pools.list(sort="invalid_sort")
except ValueError as e:
print(e) # "sort must be one of: asc, desc"
try:
# Invalid limit parameter
client.pools.list(limit=500)
except ValueError as e:
print(e) # "limit must be at most 100"
Working with Models
Show models
Show models
Copy
from dexpaprika_sdk import DexPaprikaClient
from dexpaprika_sdk.models import PoolDetails # Type hint example
client = DexPaprikaClient()
# Get pool details
pool: PoolDetails = client.pools.get_details(
network_id="ethereum",
pool_address="0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640" # USDC/WETH Uniswap v3 pool
)
# Access pool properties with type checking and auto-completion
print(f"Pool: {pool.tokens[0].symbol}/{pool.tokens[1].symbol}")
print(f"Volume (24h): ${pool.day.volume_usd:.2f}")
print(f"Transactions (24h): {pool.day.txns}")
print(f"Price: ${pool.last_price_usd:.4f}")
# Time interval data is available for multiple timeframes
print(f"1h price change: {pool.hour1.last_price_usd_change:.2f}%")
print(f"24h price change: {pool.day.last_price_usd_change:.2f}%")
# All API responses are converted to typed Pydantic models
# This provides automatic validation, serialization/deserialization,
# and IDE auto-completion support through Python type hints
Resources
API Status
The DexPaprika API provides consistent data with stable endpoints. No API key is currently required to access the service. We aim to maintain backward compatibility and provide notice of any significant changes.FAQs
Do I need an API key with this SDK?
Do I need an API key with this SDK?
No. The API is public; no keys or registration required.
How do I find identifiers?
How do I find identifiers?
Use Coverage Checker or list Networks and query Tokens/Pools to discover addresses.
How do I get historical or transactions data?
How do I get historical or transactions data?
Use pools/transactions endpoints with
pool_address
, network
, and time/paging params as documented.What about rate limiting?
What about rate limiting?
Handle retries for transient HTTP errors and keep calls reasonable for public endpoints.