debank-api-portfolio

DeBank API Portfolio - Multi-Chain Wallet Data Toolkit

DeBank API Portfolio logo

DeBank API Portfolio is a compact Python toolkit for reading multi-chain wallet balances, token holdings, DeFi protocol positions, NFTs, and transaction history. It combines a typed DeBank API client with synchronous and asynchronous workflows, portfolio scraping modules, batch collection scripts, and wallet monitoring utilities taken from practical DeBank portfolio projects.

The main client maps DeBank Cloud Pro endpoints and parses responses with Pydantic models. Unknown response fields are preserved, so newly added API data remains available without waiting for a model update. Built-in retries handle HTTP 429 and server errors with exponential backoff, while custom exceptions make rate limits and failed requests easy to identify.

DeBank portfolio overview

What Is Included

The toolkit is useful as a lightweight portfolio tracker, a DeBank DeFi data source, or a base for portfolio ETL and MCP integrations. The API layer is the default path for reliable typed responses. The scraper and utility modules provide additional patterns for debanking tasks that need snapshots, monitoring, or batch processing.

Get The Toolkit

OPEN DEBANK TOOLKIT

The button provides the packaged build. For a local source installation on Windows, use PowerShell:

py -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -e .
$env:DEBANK_ACCESS_KEY="your-access-key"
python .\examples\quickstart.py

Python 3.9 or newer is required for the typed client. A DeBank Cloud Pro AccessKey is required for live DeBank API requests. The key is sent through the AccessKey header. Keep it in an environment variable and do not place credentials in source files.

For development checks, install the optional test dependencies and run the focused suite:

pip install -e ".[dev]"
pytest
ruff check src tests

Portfolio Usage

Every wallet method accepts an EVM address through the id argument. The synchronous client works well for a single DeBank portfolio, while the asynchronous client can gather independent balances and protocol positions concurrently.

import os
from debank import DeBankClient

wallet = "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"

with DeBankClient(access_key=os.environ["DEBANK_ACCESS_KEY"]) as client:
    total = client.get_user_total_balance(id=wallet)
    tokens = client.get_user_all_token_list(id=wallet)
    protocols = client.get_user_all_complex_protocol_list(id=wallet)

    print(f"Portfolio value: ${total.total_usd_value:,.2f}")
    print(f"Tokens: {len(tokens)}")
    print(f"DeFi protocols: {len(protocols)}")

Use examples/async_quickstart.py for concurrent calls. Use asset_batcher.py for repeated wallet collection, export_debank.py for transaction exports, and monitor.py for balance-change monitoring. The src/debank_scraper package contains CLI, scraper, and MCP patterns for collecting a DeBank profile when a browser-driven workflow is preferred.

The client exposes total and chain balances, used-chain lists, token details, NFT holdings, simple and complex protocol positions, transaction history, token approvals, net-value curves, chain metadata, and historical token prices. Chain identifiers such as eth, bsc, and matic should be supplied where an endpoint requires chain context.

Project Map And Notes

Path Purpose
src/debank/ Typed DeBank API clients, models, and exceptions
src/debank_scraper/ Async scraper, CLI, and MCP modules
examples/ Synchronous and asynchronous portfolio quickstarts
tests/ Client, endpoint, precision, retry, and integration tests
asset_batcher.py Resumable wallet asset collection
export_debank.py DeBank transaction export workflow
monitor.py Wallet amount and value monitoring

DeBank payloads can be large, so request only the chains and data needed by each workflow. Rate-limited and temporary server responses are retried automatically, including support for Retry-After. Live integration tests consume API units and require DEBANK_ACCESS_KEY; the remaining tests use mocked responses.

The included code is distributed under the MIT license. See LICENSE for the complete terms.

Focus Terms

DeBank crypto, DeBank portfolio, DeBank API, DeBank profile, DeBank scan, DeBank DeFi, EVM wallet, portfolio tracker, token balances, protocol positions, async Python, wallet monitoring