Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

dexscreener-python

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dexscreener-python

Async DexScreener API client with rate limiting, 429 retry, and response caching.

pipPyPI
Version
0.1.1
Maintainers
1

dexscreener-python

async dexscreener api client for python.

rate limiting. 429 retry. response caching. request dedup. works on any chain.


extracted from a production trading system. handles rate limits gracefully.

🛡️ Why this library?

dexscreener's api is free and powerful, but:

  • 429s kill your app if you don't handle them
  • no python client exists that handles rate limits properly
  • concurrent requests for the same token waste your quota

this library solves all three:

from dexscreener import DexScreenerClient

async with DexScreenerClient() as client:
    # get all trading pairs for a token
    pairs = await client.get_token_pairs("solana", "So11111111111111111111111111111111111111112")

    for pair in pairs:
        print(f"{pair.base_token_symbol}: ${pair.price_usd} | liq: ${pair.liquidity_usd}")

429s → automatic exponential backoff (3s → 6s → 12s). duplicate requests → deduplicated into one HTTP call. results → cached with configurable TTL.

📦 Install

pip install dexscreener-python

requires python 3.11+

⚡ Features

featuredescription
any chainsolana, ethereum, base, bsc, arbitrum — anything dexscreener supports
adaptive rate limitingtoken bucket that backs off on 429 and recovers after success
global 429 cooldownone 429 pauses ALL requests briefly (prevents request storms)
response cacheconfigurable TTL per endpoint. concurrent calls share one request.
batch supportfetch up to 30 tokens in a single request
typed dataDexPairData dataclass with computed properties (buy/sell ratio, age, etc.)

🔧 Usage

💰 Token Pairs

pairs = await client.get_token_pairs("solana", token_address)

best_pair = pairs[0]  # sorted by liquidity (highest first)
print(f"Price: ${best_pair.price_usd}")
print(f"Liquidity: ${best_pair.liquidity_usd}")
print(f"24h Volume: ${best_pair.volume_24h}")
print(f"Buy/Sell 5m: {best_pair.buy_sell_ratio_5m:.2f}")
print(f"Age: {best_pair.pair_age_seconds // 3600}h")

💵 Token Price

price = await client.get_token_price("solana", token_address)
print(f"${price}")

📦 Batch Fetch (up to 30 tokens)

data = await client.get_tokens_batch("solana", [addr1, addr2, addr3])
for addr, pair in data.items():
    print(f"{pair.base_token_symbol}: ${pair.price_usd}")
results = await client.search_pairs("BONK")
for pair in results:
    print(f"{pair.base_token_symbol} on {pair.dex_id}: ${pair.price_usd}")

🚀 Boosted Tokens

boosted = await client.get_boosted_tokens("solana")
# boosted tokens are paid promotions — treat with caution

🎯 Specific Pair

pair = await client.get_pair_by_address("solana", pair_address)
print(f"{pair.dex_id}: ${pair.price_usd}")

📋 DexPairData

all methods return DexPairData objects with these fields:

fieldtypedescription
chain_idstrchain identifier
dex_idstrdex identifier (raydium, uniswap_v3, etc.)
pair_addressstrpair contract address
base_token_addressstrbase token mint/address
base_token_symbolstrtoken symbol
price_usdDecimalcurrent price in USD
price_nativeDecimalprice in native token (SOL, ETH, etc.)
liquidity_usdDecimaltotal liquidity in USD
volume_5m / 1h / 6h / 24hDecimalvolume by timeframe
price_change_5m / 1h / 6h / 24hDecimalprice change %
buys_5m / 1h / 24hintbuy transactions
sells_5m / 1h / 24hintsell transactions
pair_created_atintunix timestamp (ms)

computed properties:

propertydescription
buy_sell_ratio_5mbuy/sell ratio over 5 minutes (>1 = more buying)
buy_sell_ratio_1hbuy/sell ratio over 1 hour
has_liquidityTrue if liquidity > $1000
pair_age_secondspair age in seconds

⚙️ Configuration

client = DexScreenerClient(
    rate_limit=5.0,      # requests/second (default: 5.0, dexscreener limit is ~300/min)
    cache_ttl=8.0,       # default cache TTL in seconds
)

🆚 Comparison

dexscreener-pythonraw httpx / requests
Rate limiting✅ adaptive token bucket❌ manual
429 retry✅ exponential backoff❌ crash
Global cooldown✅ one 429 pauses all❌ per-request only
Response cache✅ TTL + dedup❌ manual
Typed dataDexPairData dataclass❌ raw dicts
Batch support✅ up to 30 tokens❌ manual loop
Async✅ nativedepends

License

MIT

📦 Also by JinUltimate1995

Keywords

api

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts