Official Python SDK for the DefiLlama API. Access DeFi protocol data including TVL, prices, yields, volumes, fees, bridges, and more.
pip install defillama-sdkuv pip install defillama-sdkfrom defillama_sdk import DefiLlama
# Free tier
client = DefiLlama()
# Pro tier (required for premium endpoints)
pro_client = DefiLlama({"api_key": "your-api-key"})
# Get all protocols
protocols = client.tvl.getProtocols()
# Get current token prices
prices = client.prices.getCurrentPrices(
[
"ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"coingecko:bitcoin",
]
)config = {
"api_key": "your-api-key",
"timeout": 30000,
}
client = DefiLlama(config)- TVL
- Prices
- Stablecoins
- Yields (Pro)
- Volumes
- Fees
- Emissions (Pro)
- Bridges (Pro)
- Ecosystem (Pro)
- ETFs (Pro)
- DAT (Pro)
- Account (Pro)
π = Requires Pro API key
Total Value Locked data for protocols and chains.
Get all protocols with current TVL.
protocols = client.tvl.getProtocols()Get detailed protocol information including historical TVL.
aave = client.tvl.getProtocol("aave")Get only current TVL for a protocol.
tvl = client.tvl.getTvl("uniswap")Get current TVL for all chains.
chains = client.tvl.getChains()Get historical TVL data.
all_history = client.tvl.getHistoricalChainTvl()
eth_history = client.tvl.getHistoricalChainTvl("Ethereum")Get protocols holding a specific token.
holders = pro_client.tvl.getTokenProtocols("ETH")Get token inflows/outflows between timestamps.
inflows = pro_client.tvl.getInflows(
"lido",
1704067200,
1704153600,
"ETH,USDC",
)Get asset breakdown for all chains.
assets = pro_client.tvl.getChainAssets()Token price data and historical charts.
prices = client.prices.getCurrentPrices(
[
"ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"coingecko:bitcoin",
"solana:So11111111111111111111111111111111111111112",
]
)prices = client.prices.getHistoricalPrices(
1704067200,
["ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7"],
)prices = client.prices.getBatchHistoricalPrices(
{
"ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": [
1704067200,
1704153600,
1704240000,
]
}
)chart = client.prices.getChart(
["coingecko:ethereum"],
{"start": 1704067200, "period": "1d", "span": 30},
)change = client.prices.getPercentageChange(
["coingecko:bitcoin"],
{"period": "24h"},
)first = client.prices.getFirstPrices(
["ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"]
)block = client.prices.getBlockAtTimestamp("ethereum", 1704067200)Stablecoin market cap and dominance data.
stables = client.stablecoins.getStablecoins(True)charts = client.stablecoins.getAllCharts()eth_charts = client.stablecoins.getChartsByChain("Ethereum")usdt = client.stablecoins.getStablecoin("1")chains = client.stablecoins.getChains()prices = client.stablecoins.getPrices()dominance = pro_client.stablecoins.getDominance("ethereum", 1)Yield farming, lending, staking, and perpetual funding rates.
Get all earn pools (pools with at least $10K supplied).
res = pro_client.yields.getEarn()
# Returns: {"as_of": str (optional), "data": List[EarnPool]}
pool = res["data"][0]
pool["protocol"] # "Aave V3" (display name, not a slug)
pool["apy"]["current"]["total"] # also apy.avg_7d / apy.avg_30d, each {base, reward, total}
pool["underlying_tokens"] # [{address, symbol, decimals}]Filter and paginate earn pools server-side. chain and protocol are slugs (up to 20 values each); rows are sorted by TVL descending.
res = pro_client.yields.queryEarn(
{
"chain": ["ethereum", "arbitrum"],
"protocol": "aave-v3",
"stablecoin": True, # also single_asset_exposure, impermanent_loss_risk
"min_tvl": 1_000_000,
"limit": 100, # 1-300, default 100
"page": 1,
}
)
# Returns: {"data": List[EarnPool], "pagination": {total, page, limit}}Get daily TVL/APY history for an earn pool. range is "30d", "90d" or "max" (default).
res = pro_client.yields.getEarnHistory("747c1d2a-c668-4682-b9f9-296708a3dd90", "30d")
# Returns: {"data": List[EarnHistoryPoint]} β {date, tvl_usd, apy: {avg_1d, avg_7d, avg_30d}, ...}Get all borrow markets with supply APY, borrow cost, LTV, and liquidity.
res = pro_client.yields.getBorrowMarkets()
# Returns: {"as_of": str (optional), "data": List[BorrowMarket]}Get daily borrow-side history for a market. range is "30d", "90d" or "max" (default).
res = pro_client.yields.getBorrowMarketHistory("e880e828-ca59-4ec6-8d4f-27182a4dc23d", "90d")
# Returns: {"data": List[BorrowMarketHistoryPoint]}Get perpetual futures funding rates, open interest and index price (Binance and OKX).
perps = pro_client.yields.getPerpFundingRates()
# Returns: {"status": str, "data": List[PerpPool]}Get liquid staking token exchange rates.
lst_rates = pro_client.yields.getLstRates()
# Returns: List[LsdRate]DEX, options, and derivatives trading volume data.
overview = client.volumes.getDexOverview()
overview = client.volumes.getDexOverview(
{"excludeTotalDataChart": True, "dataType": "dailyVolume"}
)eth_volume = client.volumes.getDexOverviewByChain("Ethereum")uniswap = client.volumes.getDexSummary("uniswap")options = client.volumes.getOptionsOverview()eth_options = client.volumes.getOptionsOverviewByChain("Ethereum")derive = client.volumes.getOptionsSummary("derive")derivatives = pro_client.volumes.getDerivativesOverview()gmx = pro_client.volumes.getDerivativesSummary("gmx")Get summary of DEX metrics with protocol list (no charts).
metrics = pro_client.volumes.getDexMetrics()
# With data type
metrics = pro_client.volumes.getDexMetrics({"dataType": "dailyVolume"})Get DEX metrics for a specific protocol.
uniswap = pro_client.volumes.getDexMetricsByProtocol("uniswap")Get summary of derivatives metrics with protocol list (no charts).
metrics = pro_client.volumes.getDerivativesMetrics()Get derivatives metrics for a specific protocol.
hyperliquid = pro_client.volumes.getDerivativesMetricsByProtocol("hyperliquid")Get summary of options metrics with protocol list (no charts).
metrics = pro_client.volumes.getOptionsMetrics()Get options metrics for a specific protocol.
hegic = pro_client.volumes.getOptionsMetricsByProtocol("hegic")Protocol fees and revenue data.
from defillama_sdk import FeeDataType
FeeDataType.DAILY_FEES
FeeDataType.DAILY_REVENUE
FeeDataType.DAILY_HOLDERS_REVENUE
FeeDataType.DAILY_SUPPLY_SIDE_REVENUE
FeeDataType.DAILY_BRIBES_REVENUE
FeeDataType.DAILY_TOKEN_TAXES
FeeDataType.DAILY_APP_FEES
FeeDataType.DAILY_APP_REVENUEfees = client.fees.getOverview()
revenue = client.fees.getOverview({"dataType": FeeDataType.DAILY_REVENUE})eth_fees = client.fees.getOverviewByChain("Ethereum")uniswap_fees = client.fees.getSummary("uniswap")chart = pro_client.fees.getChart()
eth_chart = pro_client.fees.getChartByChain("Ethereum")
protocol_chart = pro_client.fees.getChartByProtocol("aave")breakdown = pro_client.fees.getChartByProtocolChainBreakdown("aave")breakdown = pro_client.fees.getChartByProtocolVersionBreakdown("uniswap")breakdown = pro_client.fees.getChartByChainProtocolBreakdown("Ethereum")breakdown = pro_client.fees.getChartChainBreakdown()metrics = pro_client.fees.getMetrics()
chain_metrics = pro_client.fees.getMetricsByChain("Ethereum")
protocol_metrics = pro_client.fees.getMetricsByProtocol("aave")Token unlock schedules and vesting data.
emissions = pro_client.emissions.getAll()arbitrum = pro_client.emissions.getByProtocol("arbitrum")Cross-chain bridge volume and transaction data.
bridges = pro_client.bridges.getAll()
bridges = pro_client.bridges.getAll({"includeChains": True})bridge = pro_client.bridges.getById(1)volume = pro_client.bridges.getVolumeByChain("Ethereum")stats = pro_client.bridges.getDayStats(1704067200, "Ethereum")txs = pro_client.bridges.getTransactions(
1,
{
"limit": 100,
"startTimestamp": 1704067200,
"endTimestamp": 1704153600,
"sourceChain": "Ethereum",
"address": "0x...",
},
)Ecosystem-level data.
categories = pro_client.ecosystem.getCategories()forks = pro_client.ecosystem.getForks()oracles = pro_client.ecosystem.getOracles()entities = pro_client.ecosystem.getEntities()treasuries = pro_client.ecosystem.getTreasuries()hacks = pro_client.ecosystem.getHacks()raises = pro_client.ecosystem.getRaises()Bitcoin and Ethereum ETF data.
btc_etfs = pro_client.etfs.getOverview()eth_etfs = pro_client.etfs.getOverviewEth()history = pro_client.etfs.getHistory()history_eth = pro_client.etfs.getHistoryEth()perf = pro_client.etfs.getFdvPerformance("30")Digital Asset Treasury data and institutional holdings.
data = pro_client.dat.getInstitutions()mstr = pro_client.dat.getInstitution("MSTR")API usage management.
usage = pro_client.account.getUsage()from defillama_sdk import ApiKeyRequiredError, RateLimitError, NotFoundError, ApiError
try:
data = pro_client.yields.getEarn()
except ApiKeyRequiredError:
print("Pro API key required for this endpoint")
except RateLimitError as exc:
print(f"Rate limited. Retry after {exc.retry_after} seconds")
except NotFoundError:
print("Resource not found")
except ApiError as exc:
print(f"API error: {exc.status_code}")All types are available from defillama_sdk.types, and are re-exported at the top level:
from defillama_sdk import (
Protocol,
CoinPricesResponse,
Stablecoin,
# Yields
EarnPool,
EarnHistoryPoint,
EarnQueryParams,
BorrowMarket,
BorrowMarketHistoryPoint,
PerpPool,
LsdRate,
YieldPool, # deprecated (v1)
BorrowPool, # deprecated (v1)
)from defillama_sdk import AdapterType, FeeDataType, VolumeDataType
AdapterType.DEXS
VolumeDataType.DAILY_VOLUME
FeeDataType.DAILY_FEES- Python >= 3.9
MIT