Skip to main content

Pandas API client for CoinGecko

Project description

coingecko-pandas

Pandas API client for CoinGecko

A pandas-style Python client for the CoinGecko REST and WebSocket APIs. Every list endpoint returns a pandas.DataFrame, every dict endpoint returns a TypedDict, and every shape is enforced by a pandera schema. Sync + async, with optional Streamlit explorer and FastMCP server extras.

Install

uv pip install coingecko-pandas              # core
uv pip install "coingecko-pandas[ws]"        # + WebSocket
uv pip install "coingecko-pandas[explorer]"  # + Streamlit dashboard
uv pip install "coingecko-pandas[mcp]"       # + FastMCP server
uv pip install "coingecko-pandas[dev]"       # + test/lint toolchain

Quickstart

Sync

from coingecko_pandas import CoinGeckoPandas

with CoinGeckoPandas() as client:
    # Top 10 by market cap
    df = client.coins_markets("usd", per_page=10, page=1)
    print(df[["id", "symbol", "currentPrice", "marketCap"]])

    # Bitcoin OHLC last day
    ohlc = client.coins_id_ohlc("bitcoin", vs_currency="usd", days="1")
    print(ohlc.tail())

Async

import asyncio
from coingecko_pandas import AsyncCoinGeckoPandas

async def main():
    async with AsyncCoinGeckoPandas() as client:
        markets, ohlc = await asyncio.gather(
            client.coins_markets("usd", per_page=10, page=1),
            client.coins_id_ohlc("bitcoin", vs_currency="usd", days="1"),
        )
        print(markets.head())
        print(ohlc.tail())

asyncio.run(main())

Authentication

CoinGecko offers two API tiers. The repo ships an .env.example — copy it to .env, fill in your keys, and any example/test that calls load_dotenv() will pick them up automatically:

cp .env.example .env
$EDITOR .env

Or set them directly in your shell:

# Demo (free) tier
export COINGECKO_DEMO_API_KEY=...

# Pro tier (auto-switches base URL to pro-api.coingecko.com)
export COINGECKO_PRO_API_KEY=...

Or pass via the constructor:

CoinGeckoPandas(api_key="demo-key")
CoinGeckoPandas(pro_api_key="pro-key")

The Pro key takes precedence and switches the base URL to https://pro-api.coingecko.com/api/v3/. The client reads env vars in __post_init__, so as long as .env is loaded before instantiation, you don't need to pass anything explicitly.

Endpoints

All 41 CoinGecko Demo API endpoints are exposed across 14 mixin classes (one per OpenAPI tag):

Mixin Methods
PingMixin ping_server
SimpleMixin simple_price, simple_token_price, simple_supported_currencies
CoinsMixin coins_list, coins_markets, coins_id, coins_id_tickers, coins_id_history, coins_id_market_chart, coins_id_market_chart_range, coins_id_ohlc
ContractMixin coins_contract_address, contract_address_market_chart, contract_address_market_chart_range
AssetPlatformsMixin asset_platforms_list, token_lists
CategoriesMixin coins_categories_list, coins_categories
ExchangesMixin exchanges, exchanges_list, exchanges_id, exchanges_id_tickers, exchanges_id_volume_chart
DerivativesMixin derivatives_tickers, derivatives_exchanges, derivatives_exchanges_list, derivatives_exchanges_id
NFTsMixin nfts_list, nfts_id, nfts_contract_address
ExchangeRatesMixin exchange_rates
SearchMixin search_data
TrendingMixin trending_search
GlobalMixin crypto_global, global_defi
PublicTreasuryMixin entities_list, public_treasury_entity, public_treasury_transaction_history, public_treasury_entity_chart, companies_public_treasury

WebSockets (Pro tier)

CoinGecko publishes 4 channels (Pro only):

Method Channel Code
subscribe_simple_price CGSimplePrice C1
subscribe_onchain_token_price OnchainSimpleTokenPrice G1
subscribe_onchain_trade OnchainTrade G2
subscribe_onchain_ohlcv OnchainOHLCV G3
from coingecko_pandas import CoinGeckoPandas, CoinGeckoWebSocket

client = CoinGeckoPandas(pro_api_key="...")
ws = CoinGeckoWebSocket.from_client(client)

with ws.subscribe_simple_price(coins=["bitcoin"]) as session:
    ...

The exact WebSocket connection URL and subscribe payload format are not in the public docs at the time of generation. Verify against the CoinGecko Pro dashboard before relying on this in production.

Error handling

from coingecko_pandas import (
    CoinGeckoAPIError,
    CoinGeckoAuthError,
    CoinGeckoRateLimitError,
)

try:
    df = client.coins_markets("usd")
except CoinGeckoAuthError:
    ...
except CoinGeckoRateLimitError:
    ...
except CoinGeckoAPIError as e:
    print(e.status_code, e.url, e.detail)

Development

uv pip install -e ".[dev]"
uv run pytest tests/test_unit.py tests/test_async_unit.py -v
uv run ruff check coingecko_pandas
uv run mypy coingecko_pandas

CI runs the same checks on every push and PR via .github/workflows/ci.yml across Python 3.11, 3.12, and 3.13.

To run the live integration tests:

PYTEST_LIVE=1 uv run pytest tests/test_integration.py -v

Releasing

Releases are cut by pushing a v* tag. .github/workflows/release.yml then:

  1. Builds sdist + wheel via uv build
  2. Publishes to PyPI via trusted publishing (OIDC, no API token in secrets)
  3. Creates a GitHub release with the built artifacts attached

One-time setup (before the first release):

  1. Reserve the coingecko-pandas name on PyPI.
  2. Visit https://pypi.org/manage/account/publishing/ and add a pending publisher:
    • PyPI project name: coingecko-pandas
    • Owner: sigma-quantiphi
    • Repository: coingecko-pandas
    • Workflow: release.yml
    • Environment: pypi
  3. In the GitHub repo settings, create an Environment named pypi.

To cut a release:

# 1. Move [Unreleased] entries under a new version header in CHANGELOG.md
# 2. Bump version in pyproject.toml
# 3. Commit, tag, push
git commit -am "Release v0.1.1"
git tag v0.1.1
git push origin main --tags

Generated by

This package was scaffolded by the api-pandas Claude Code skill from the official CoinGecko OpenAPI spec.

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coingecko_pandas-0.1.1.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coingecko_pandas-0.1.1-py3-none-any.whl (34.8 kB view details)

Uploaded Python 3

File details

Details for the file coingecko_pandas-0.1.1.tar.gz.

File metadata

  • Download URL: coingecko_pandas-0.1.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for coingecko_pandas-0.1.1.tar.gz
Algorithm Hash digest
SHA256 bb87ee26248321feba276623389803a272994d3740838e2f4867a68067edd777
MD5 68e3216aa98de34ec39fa71d81932d06
BLAKE2b-256 9fae4e1e117c6a01b012353a13c57930744568421aefd78ff30428b9f464d559

See more details on using hashes here.

Provenance

The following attestation bundles were made for coingecko_pandas-0.1.1.tar.gz:

Publisher: release.yml on sigma-quantiphi/coingecko-pandas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coingecko_pandas-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for coingecko_pandas-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 80b5752da1b497f4ac560f2cd7254c35ca75c251c5baeff7fe31b261a4a0e3d3
MD5 76a11f52936b4dbc4edff2f967b6f521
BLAKE2b-256 bf099684094f93ceb1679d62db16e9009bba4cabd8c7fde7c6db5756d70c8d99

See more details on using hashes here.

Provenance

The following attestation bundles were made for coingecko_pandas-0.1.1-py3-none-any.whl:

Publisher: release.yml on sigma-quantiphi/coingecko-pandas

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page