Skip to main content

coinmarketcap-sdk

PyPI version

The official Python SDK for the CoinMarketCap Pro API.

Installation

pip install coinmarketcap-sdk
# or
uv add coinmarketcap-sdk
# or
poetry add coinmarketcap-sdk

Note: The PyPI package is coinmarketcap-sdk, but you import it as coinmarketcap:

from coinmarketcap import CoinMarketCap

Quick Start

import os
from coinmarketcap import CoinMarketCap

cmc = CoinMarketCap(api_key=os.environ["CMC_PRO_API_KEY"])

# Use the namespace API — discover endpoints by category with autocomplete
quotes = cmc.cryptocurrency.quotes_latest(id="1,1027")  # 1 = BTC, 1027 = ETH
print(quotes)

Usage

Namespace API (Recommended)

All endpoints are grouped by category on the client instance:

from coinmarketcap import CoinMarketCap

cmc = CoinMarketCap(api_key="your-key")

cmc.cryptocurrency.quotes_latest(id="1")
cmc.cryptocurrency.listings_latest(limit=10)
cmc.global_metrics.quotes_latest()
cmc.exchange.info(id="270")

Async variants are available with the async_ prefix:

quotes = await cmc.cryptocurrency.async_quotes_latest(id="1,1027")

POST Endpoints (Request Models)

POST endpoints require typed request body models:

from coinmarketcap import CoinMarketCap
from coinmarketcap.models import DqueryBatchPriceRequestDTO

cmc = CoinMarketCap(api_key="your-key")

body = DqueryBatchPriceRequestDTO.from_dict({
    "tokens": [{"platform": "ethereum", "address": "0x..."}],
})
prices = cmc.token.batch_get_token_price(body=body)

All 400+ request/response models are available via coinmarketcap.models.

Configuration Options

cmc = CoinMarketCap(
    # Required for 'pro' mode
    api_key="your-api-key",

    # Optional
    environment="pro",      # 'pro' (default) or 'public'
    base_url=None,          # Override base URL entirely
    timeout=30.0,           # Request timeout in seconds (default: 30s)
    max_retries=2,          # Auto-retry count (default: 2)
)

Public (Keyless) Mode

Use the public API without an API key for publicly available endpoints:

from coinmarketcap import CoinMarketCap

cmc = CoinMarketCap(environment="public")

cmc.cryptocurrency.listings_latest(limit=10)

Error Handling

The SDK raises typed exception classes for common HTTP failures:

from coinmarketcap import CoinMarketCap, CMCError, RateLimitError, AuthenticationError

cmc = CoinMarketCap(api_key="your-key")

try:
    quotes = cmc.cryptocurrency.quotes_latest(id="1")
except RateLimitError as e:
    print("Rate limited:", e)
except AuthenticationError as e:
    print("Invalid API key:", e)
except CMCError as e:
    print(f"API error {e.status_code}:", e)

Error Types

Status Code Error Class
400 BadRequestError
401 AuthenticationError
402 PaymentRequiredError
403 ForbiddenError
404 NotFoundError
429 RateLimitError
5xx InternalServerError
Network APIConnectionError
Timeout APITimeoutError

Automatic Retries

Requests that fail with retryable status codes are automatically retried with exponential backoff:

  • Retryable: 408, 409, 429, 500, 502, 503, 504, and network errors
  • Default: 2 retries with 500ms initial delay, up to 8s max
  • 429 responses: Respects the Retry-After header when present

Disable retries:

cmc = CoinMarketCap(api_key="your-key", max_retries=0)

Timeout

Requests time out after 30 seconds by default:

cmc = CoinMarketCap(api_key="your-key", timeout=10.0)  # 10 seconds

Available Endpoints

All endpoints are available via cmc.<category>.<method>(). Categories include:

  • cmc.cryptocurrency — Quotes, listings, market pairs, OHLCV, categories
  • cmc.exchange — Exchange info, listings, market pairs
  • cmc.global_metrics — Global stats, fear & greed index
  • cmc.content — News, posts
  • cmc.community — Trending tokens, topics
  • cmc.token — DEX token data, pools, trades
  • cmc.derivatives — Derivatives market data
  • cmc.cmc_index — CMC 20/100 index

Requirements

  • Python >= 3.10

License

MIT

Download files

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

Source Distribution

coinmarketcap_sdk-4.0.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

coinmarketcap_sdk-4.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file coinmarketcap_sdk-4.0.1.tar.gz.

File metadata

  • Download URL: coinmarketcap_sdk-4.0.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.6

File hashes

Hashes for coinmarketcap_sdk-4.0.1.tar.gz
Algorithm Hash digest
SHA256 4958f7845d6210514b50aeedc9da161d55417b166a7a3fa681044f3cd944c957
MD5 4b6aba4e05dab8e62f4b9a79140cb410
BLAKE2b-256 0fa80b36ca7cea9434f4952cabbafbed52be7f49447afa458254b40841140ee5

See more details on using hashes here.

File details

Details for the file coinmarketcap_sdk-4.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for coinmarketcap_sdk-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2dbb99bf64aabaf602aa9e9a5143a26d35f0a3777e8e05b32cc2523d42f8cbe9
MD5 1ef27b285e31e032c077fa4cb9ff5a08
BLAKE2b-256 7a8def5a9601f8905e3f49a4c49265fd3e743f943ce23bec83fd20bbe479e1ce

See more details on using hashes here.

Supported by

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