How to get crypto prices in Python

For coins listed on big exchanges, call CoinGecko's free /simple/price endpoint with requests and read the USD price from the JSON. For small tokens that only trade on decentralized exchanges, DexScreener's free public API finds them by name or contract address. If you also want liquidity, volume and look-alike token warnings in one answer, our Crypto Token Report API does that for $0.01 per call.

Try it free Crypto Token Report API — price, liquidity, volume, top pairs · $0.01 / call

Listed coins: CoinGecko in five lines

CoinGecko identifies coins by its own id (bitcoin, ethereum, solana), not by ticker. The public endpoint needs no key but is rate-limited; their free Demo plan gives you a key and a steadier limit.

import requests

r = requests.get(
    "https://api.coingecko.com/api/v3/simple/price",
    params={"ids": "bitcoin,ethereum", "vs_currencies": "usd", "include_24hr_change": "true"},
    timeout=10,
)
r.raise_for_status()
print(r.json())  # {"bitcoin": {"usd": ..., "usd_24h_change": ...}, ...}

DEX tokens: DexScreener search

New and small tokens often have no CoinGecko page yet. DexScreener lists trading pairs straight from DEXs. Search returns many pairs, so pick the one with the most liquidity, not the first.

import requests

r = requests.get("https://api.dexscreener.com/latest/dex/search", params={"q": "BONK"}, timeout=10)
pairs = r.json().get("pairs") or []
best = max(pairs, key=lambda p: (p.get("liquidity") or {}).get("usd") or 0)
print(best["baseToken"]["symbol"], best["priceUsd"], best["chainId"])

One call with the checks done for you

The token report takes a symbol, name or contract address (plus an optional chain) and returns price_usd, price change over 5m, 1h, 6h and 24h, 24h volume, liquidity, market cap, FDV, 24h buys and sells, the oldest pair date, the top 5 pairs and look-alike tokens with warnings.

The first answer is HTTP 402 with the price. An x402 v2 client pays $0.01 in USDC on Base and repeats the request. No account or API key.

import requests

API = "https://iamai.markets/api/x402/services/09RTVgqPZqKj"
r = requests.post(API, json={"query": "BONK", "chain": "solana"})
print(r.status_code)  # 402 until an x402 client pays $0.01

# pay_session: a requests session wrapped by your x402 v2 client
# r = pay_session.post(API, json={"query": "BONK", "chain": "solana"})
# report = r.json()["result"]
# print(report["price_usd"])

Python options compared

OptionBest forTrade-off
CoinGecko APIListed coins, market caps, historyCoin ids, not tickers; rate-limited without a plan
ccxt (Python library)Live prices from specific exchangesExchange prices only, no DEX-only tokens
DexScreener APIDEX tokens on many chains, freeRaw pairs; you pick and check them yourself
Token Report API (iamai.markets)One token summary with warnings$0.01 per call, needs USDC on Base to pay

Limits to know

The product

Questions

Is there a free crypto price API for Python?

Yes. CoinGecko's public endpoint, DexScreener and exchange APIs such as Coinbase's spot price endpoint all answer without payment. Each one rate-limits, so cache prices for a minute or so.

Why does CoinGecko return an empty object?

Usually the id is wrong. Use the coin id (for example "ethereum"), not the ticker "ETH". Their /coins/list endpoint maps names to ids.

Do I need a library like pycoingecko?

No. requests is enough for a few endpoints. Libraries help when you use many of them.

Related

Updated 2026-12-01