Skip to main content

DefiLlama Python SDK

Official Python SDK for the DefiLlama API. Access DeFi protocol data including TVL, prices, yields, volumes, fees, bridges, and more.

Installation

pip install defillama-sdk
uv pip install defillama-sdk

Quick Start

from 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",
    ]
)

Configuration

config = {
    "api_key": "your-api-key",
    "timeout": 30000,
}

client = DefiLlama(config)

Modules

  • TVL
  • Prices
  • Stablecoins
  • Yields (Pro)
  • Volumes
  • Fees
  • Emissions (Pro)
  • Bridges (Pro)
  • Ecosystem (Pro)
  • ETFs (Pro)
  • DAT (Pro)
  • Account (Pro)

🔐 = Requires Pro API key


TVL

Total Value Locked data for protocols and chains.

getProtocols

Get all protocols with current TVL.

protocols = client.tvl.getProtocols()

getProtocol

Get detailed protocol information including historical TVL.

aave = client.tvl.getProtocol("aave")

getTvl

Get only current TVL for a protocol.

tvl = client.tvl.getTvl("uniswap")

getChains

Get current TVL for all chains.

chains = client.tvl.getChains()

getHistoricalChainTvl

Get historical TVL data.

all_history = client.tvl.getHistoricalChainTvl()
eth_history = client.tvl.getHistoricalChainTvl("Ethereum")

getTokenProtocols 🔐

Get protocols holding a specific token.

holders = pro_client.tvl.getTokenProtocols("ETH")

getInflows 🔐

Get token inflows/outflows between timestamps.

inflows = pro_client.tvl.getInflows(
    "lido",
    1704067200,
    1704153600,
    "ETH,USDC",
)

getChainAssets 🔐

Get asset breakdown for all chains.

assets = pro_client.tvl.getChainAssets()

Prices

Token price data and historical charts.

getCurrentPrices

prices = client.prices.getCurrentPrices(
    [
        "ethereum:0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
        "coingecko:bitcoin",
        "solana:So11111111111111111111111111111111111111112",
    ]
)

getHistoricalPrices

prices = client.prices.getHistoricalPrices(
    1704067200,
    ["ethereum:0xdac17f958d2ee523a2206206994597c13d831ec7"],
)

getBatchHistoricalPrices

prices = client.prices.getBatchHistoricalPrices(
    {
        "ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": [
            1704067200,
            1704153600,
            1704240000,
        ]
    }
)

getChart

chart = client.prices.getChart(
    ["coingecko:ethereum"],
    {"start": 1704067200, "period": "1d", "span": 30},
)

getPercentageChange

change = client.prices.getPercentageChange(
    ["coingecko:bitcoin"],
    {"period": "24h"},
)

getFirstPrices

first = client.prices.getFirstPrices(
    ["ethereum:0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48"]
)

getBlockAtTimestamp

block = client.prices.getBlockAtTimestamp("ethereum", 1704067200)

Stablecoins

Stablecoin market cap and dominance data.

getStablecoins

stables = client.stablecoins.getStablecoins(True)

getAllCharts

charts = client.stablecoins.getAllCharts()

getChartsByChain

eth_charts = client.stablecoins.getChartsByChain("Ethereum")

getStablecoin

usdt = client.stablecoins.getStablecoin("1")

getChains

chains = client.stablecoins.getChains()

getPrices

prices = client.stablecoins.getPrices()

getDominance 🔐

dominance = pro_client.stablecoins.getDominance("ethereum", 1)

Yields 🔐

Yield farming, lending, staking, and perpetual funding rates.

getEarn

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}]

queryEarn

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}}

getEarnHistory

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}, ...}

getBorrowMarkets

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]}

getBorrowMarketHistory

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]}

getPerpFundingRates

Get perpetual futures funding rates, open interest and index price (Binance and OKX).

perps = pro_client.yields.getPerpFundingRates()
# Returns: {"status": str, "data": List[PerpPool]}

getLstRates

Get liquid staking token exchange rates.

lst_rates = pro_client.yields.getLstRates()
# Returns: List[LsdRate]

Volumes

DEX, options, and derivatives trading volume data.

getDexOverview

overview = client.volumes.getDexOverview()
overview = client.volumes.getDexOverview(
    {"excludeTotalDataChart": True, "dataType": "dailyVolume"}
)

getDexOverviewByChain

eth_volume = client.volumes.getDexOverviewByChain("Ethereum")

getDexSummary

uniswap = client.volumes.getDexSummary("uniswap")

getOptionsOverview

options = client.volumes.getOptionsOverview()

getOptionsOverviewByChain

eth_options = client.volumes.getOptionsOverviewByChain("Ethereum")

getOptionsSummary

derive = client.volumes.getOptionsSummary("derive")

getDerivativesOverview 🔐

derivatives = pro_client.volumes.getDerivativesOverview()

getDerivativesSummary 🔐

gmx = pro_client.volumes.getDerivativesSummary("gmx")

getDexMetrics 🔐

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"})

getDexMetricsByProtocol 🔐

Get DEX metrics for a specific protocol.

uniswap = pro_client.volumes.getDexMetricsByProtocol("uniswap")

getDerivativesMetrics 🔐

Get summary of derivatives metrics with protocol list (no charts).

metrics = pro_client.volumes.getDerivativesMetrics()

getDerivativesMetricsByProtocol 🔐

Get derivatives metrics for a specific protocol.

hyperliquid = pro_client.volumes.getDerivativesMetricsByProtocol("hyperliquid")

getOptionsMetrics 🔐

Get summary of options metrics with protocol list (no charts).

metrics = pro_client.volumes.getOptionsMetrics()

getOptionsMetricsByProtocol 🔐

Get options metrics for a specific protocol.

hegic = pro_client.volumes.getOptionsMetricsByProtocol("hegic")

Fees

Protocol fees and revenue data.

Fee Data Types

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_REVENUE

getOverview

fees = client.fees.getOverview()
revenue = client.fees.getOverview({"dataType": FeeDataType.DAILY_REVENUE})

getOverviewByChain

eth_fees = client.fees.getOverviewByChain("Ethereum")

getSummary

uniswap_fees = client.fees.getSummary("uniswap")

getChart 🔐

chart = pro_client.fees.getChart()
eth_chart = pro_client.fees.getChartByChain("Ethereum")
protocol_chart = pro_client.fees.getChartByProtocol("aave")

getChartByProtocolChainBreakdown 🔐

breakdown = pro_client.fees.getChartByProtocolChainBreakdown("aave")

getChartByProtocolVersionBreakdown 🔐

breakdown = pro_client.fees.getChartByProtocolVersionBreakdown("uniswap")

getChartByChainProtocolBreakdown 🔐

breakdown = pro_client.fees.getChartByChainProtocolBreakdown("Ethereum")

getChartChainBreakdown 🔐

breakdown = pro_client.fees.getChartChainBreakdown()

getMetrics 🔐

metrics = pro_client.fees.getMetrics()
chain_metrics = pro_client.fees.getMetricsByChain("Ethereum")
protocol_metrics = pro_client.fees.getMetricsByProtocol("aave")

Emissions 🔐

Token unlock schedules and vesting data.

getAll

emissions = pro_client.emissions.getAll()

getByProtocol

arbitrum = pro_client.emissions.getByProtocol("arbitrum")

Bridges 🔐

Cross-chain bridge volume and transaction data.

getAll

bridges = pro_client.bridges.getAll()
bridges = pro_client.bridges.getAll({"includeChains": True})

getById

bridge = pro_client.bridges.getById(1)

getVolumeByChain

volume = pro_client.bridges.getVolumeByChain("Ethereum")

getDayStats

stats = pro_client.bridges.getDayStats(1704067200, "Ethereum")

getTransactions

txs = pro_client.bridges.getTransactions(
    1,
    {
        "limit": 100,
        "startTimestamp": 1704067200,
        "endTimestamp": 1704153600,
        "sourceChain": "Ethereum",
        "address": "0x...",
    },
)

Ecosystem 🔐

Ecosystem-level data.

getCategories

categories = pro_client.ecosystem.getCategories()

getForks

forks = pro_client.ecosystem.getForks()

getOracles

oracles = pro_client.ecosystem.getOracles()

getEntities

entities = pro_client.ecosystem.getEntities()

getTreasuries

treasuries = pro_client.ecosystem.getTreasuries()

getHacks

hacks = pro_client.ecosystem.getHacks()

getRaises

raises = pro_client.ecosystem.getRaises()

ETFs 🔐

Bitcoin and Ethereum ETF data.

getOverview

btc_etfs = pro_client.etfs.getOverview()

getOverviewEth

eth_etfs = pro_client.etfs.getOverviewEth()

getHistory

history = pro_client.etfs.getHistory()

getHistoryEth

history_eth = pro_client.etfs.getHistoryEth()

getFdvPerformance

perf = pro_client.etfs.getFdvPerformance("30")

DAT 🔐

Digital Asset Treasury data and institutional holdings.

getInstitutions

data = pro_client.dat.getInstitutions()

getInstitution

mstr = pro_client.dat.getInstitution("MSTR")

Account 🔐

API usage management.

getUsage

usage = pro_client.account.getUsage()

Error Handling

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}")

Type Exports

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)
)

Constants

from defillama_sdk import AdapterType, FeeDataType, VolumeDataType

AdapterType.DEXS
VolumeDataType.DAILY_VOLUME
FeeDataType.DAILY_FEES

Requirements

  • Python >= 3.9

License

MIT

Metadata

Release files for defillama-sdk 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for defillama-sdk 0.1.5
File Size Uploaded Provenance Actions
defillama_sdk-0.1.5.tar.gz 28.6 kB Without provenance Details for defillama_sdk-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for defillama-sdk 0.1.5
File Interpreter ABI Platform Actions
defillama_sdk-0.1.5-py3-none-any.whl Python 3 none any Details for defillama_sdk-0.1.5-py3-none-any.whl

Total release size: 63.9 kB

Release files / defillama_sdk-0.1.5.tar.gz

Download URL defillama_sdk-0.1.5.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
16174abea6bbf8e9db55ad6d21fe5dacba1f630d45e9686321e497fba0be98f2
BLAKE2b-256 checksum
How to use checksums
249fe4a6c7cc9efb3d06cc27aa59a11b39792dc5a84bd1a292b304bc97b1ce98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.9

Release files / defillama_sdk-0.1.5-py3-none-any.whl

Download URL defillama_sdk-0.1.5-py3-none-any.whl
Size 35.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c38bb1c809d9b4e1f8198b0656823e66e9a308521fec68bc598e9dab4fea352
BLAKE2b-256 checksum
How to use checksums
ac30b957631b1621554e4416b6c7bbf9e70f2421119860914275f88f65c2492b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.9

Security for defillama-sdk 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page