Pycoingecko Python Client
Pycoingecko is a Python wrapper around the CoinGecko API (V3), simplifying access to cryptocurrency market data. It supports both the Public and Pro API tiers. The library is actively maintained, with version 3.2.0 released on November 12, 2024, and maintains a regular release cadence.
Warnings
- gotcha Public API Rate Limits: The free Public API has a strict rate limit of approximately 30 calls per minute. Exceeding this limit will result in 429 (Too Many Requests) errors. For higher throughput, consider using a Demo or Pro API key.
- gotcha Coin IDs vs. Symbols: The CoinGecko API often requires specific CoinGecko IDs (e.g., 'bitcoin') for queries, rather than common ticker symbols (e.g., 'BTC'). Directly querying with symbols for detailed market data endpoints (like /simple/price) may not work as expected due to non-unique symbols.
- breaking Market Cap Rank Changes for Rehypothecated Tokens: Effective February 4th, 2026, the `market_cap_rank` field will return null for rehypothecated tokens. A new field, `market_cap_rank_with_rehypothecated`, is available to include these tokens in ranking calculations.
- gotcha Missing Output in Console: When using the `pycoingecko` client methods, the return value is often a dictionary. If you don't explicitly `print()` the result, no output will appear in the console.
- gotcha Floating-point Precision for Low-Value Assets: For cryptocurrencies with extremely low prices (e.g., 0.00000001), standard floating-point parsers in Python might convert these to scientific notation or round them down to zero.
Install
-
pip install -U pycoingecko
Imports
- CoinGeckoAPI
from pycoingecko import CoinGeckoAPI
Quickstart
import os
from pycoingecko import CoinGeckoAPI
# For Public API (no key required, but rate-limited)
# For Demo API with key: cg = CoinGeckoAPI(demo_api_key=os.environ.get('COINGECKO_DEMO_API_KEY', ''))
# For Pro API with key: cg = CoinGeckoAPI(api_key=os.environ.get('COINGECKO_PRO_API_KEY', ''))
cg = CoinGeckoAPI()
try:
price_data = cg.get_price(ids='bitcoin', vs_currencies='usd')
print(f"Bitcoin price in USD: {price_data.get('bitcoin', {}).get('usd')}")
status = cg.ping()
print(f"API Status: {status}")
except Exception as e:
print(f"An error occurred: {e}")