Skip to main content

Unofficial Python wrapper for DeFi Llama API client using PyCurl module.

Reason this release was yanked:

Deprecated API release

Project description

DeFiLlama Python API

Python 3.6 Python 3.7 Python 3.8 Python 3.9

License


Unofficial Python wrapper for the DeFi Llama API using PyCurl module

Inspired from itzmestar's DeFi Llama Python API.

For detailed information about the API endpoints, see DeFi Llama API Documentation

Installation:

Use pip to install:

pip install DeFiLlama-Curl

Authentication:

Endpoints are accessible without an API key.


Documentation:

To import the package and initialize API client

# Import library
from defillama import defillama

# Client object to interact with DeFi Llama API
llama = DefiLlama()

TVL : Retrieve TVL data -->

  1. GET/protocols : List all protocols on defillama along with their TVL.
llama.get_protocols()
  1. GET/protocol/{protocol} : Get historical TVL of a protocol and breakdown by token and chain.
# For e.g. aave
llama.get_protocol(protocol='aave')
  1. GET/charts : Get historical TVL of DeFi on all chains.
llama.get_charts()
  1. GET/charts/{chain} : Get historical TVL of a chain.
    Chains can be obtained from GET/chains or the chains property on GET/protocols.
# For e.g. Ethereum
llama.get_chart(chain='Ethereum')
  1. GET/tvl/{protocol} : Get only protocol TVL as a number.
# For e.g. uniswap
llama.get_tvl_protocol(protocol='uniswap')
  1. GET/chains : Get current TVL of all chains.
llama.get_chains()

coins : General blockchain data used by DeFi Llama and open-sourced -->

  1. GET/block/{chain}/{timestamp} : Get the closest block on a timestamp (UNIX formatted).
    Runs binary search over a blockchain's blocks to get the closest one to a timestamp.
    Every time this is run DeFi Llama adds new data to their database, so each query permanently speeds up future queries.
# For e.g. Fantom chain for timestamp 1650207158
llama.get_block_timestamp(block='fantom', timestamp=1650207158)
  1. POST/prices : Get current or historical prices of tokens by contract address.
    If timestamp is not provided we just return the latest data.
# Sample data JSON
body = {
  "coins": [
    "ethereum:0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
    "avax:0xd586e7f844cea2f87f50152665bcbc2c279d8d70"
  ],
  "timestamp": 1603964988
}

# API usage
llama.post_prices(data=body)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

DeFiLlama-Curl-1.1.tar.gz (8.3 kB view hashes)

Uploaded Source

Built Distribution

DeFiLlama_Curl-1.1-py3-none-any.whl (8.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page