Pycoingecko Python Client

3.2.0 · active · verified Wed Apr 15

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

Install

Imports

Quickstart

Initializes the CoinGeckoAPI client and fetches the current price of Bitcoin in USD. It also includes a basic API status check. Users with Demo or Pro API keys should pass them during client initialization for higher rate limits and access to more endpoints.

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}")

view raw JSON →