SDKs overview
CoinMarketCap provides an API to access cryptocurrency market data, including real-time prices, historical data, and exchange information. To facilitate integration for developers, a range of Software Development Kits (SDKs) and community-contcontributed libraries are available. These tools abstract the underlying HTTP requests and JSON parsing, allowing developers to interact with the CoinMarketCap API using native language constructs rather than direct API calls. The API requires an API key for all requests, which is managed through the CoinMarketCap developer portal CoinMarketCap API documentation. Rate limits vary by subscription tier, with detailed information available on the CoinMarketCap API pricing page.
SDKs typically handle authentication, request formatting, response parsing, and error handling, streamlining the development process. The official CoinMarketCap API documentation includes examples in several languages, and community efforts have extended support to additional programming environments, enhancing the accessibility of CoinMarketCap data for various application types. Developers integrating with external APIs often utilize SDKs to reduce boilerplate code and ensure adherence to API specifications, as outlined in general API design principles Swagger API design best practices.
Official SDKs by language
CoinMarketCap supports a range of programming languages through official and well-documented community libraries. These SDKs are designed to provide a consistent and idiomatic way to interact with the CoinMarketCap API. The primary languages with direct support and extensive examples include Python and JavaScript, reflecting their widespread use in data science, web development, and backend services. Other languages like PHP, Ruby, Java, Go, and C# also have established libraries, often maintained by the community with active contributions.
The following table outlines key official and widely-used community SDKs, their typical package names, and common installation methods:
| Language | Package/Library Name | Installation Command | Maturity/Type |
|---|---|---|---|
| Python | coinmarketcap (community) |
pip install python-coinmarketcap |
Community-maintained, active |
| JavaScript | coinmarketcap-api-v2 (community) |
npm install coinmarketcap-api-v2 |
Community-maintained, active |
| PHP | php-coinmarketcap-api (community) |
composer require phatpham9/php-coinmarketcap-api |
Community-maintained |
| Ruby | coinmarketcap-ruby (community) |
gem install coinmarketcap-ruby |
Community-maintained |
| Java | coinmarketcap-java (community) |
Maven/Gradle dependency (see project docs) | Community-maintained |
| Go | go-coinmarketcap (community) |
go get github.com/miguelmota/go-coinmarketcap |
Community-maintained |
| C# | CoinMarketCap.Net (community) |
Install-Package CoinMarketCap.Net |
Community-maintained |
Installation
Installing a CoinMarketCap SDK or library typically involves using the package manager specific to your programming language. Before installation, ensure you have the correct language runtime and package manager set up in your development environment. For all API interactions, an API key is required, which can be obtained by signing up on the official CoinMarketCap API website CoinMarketCap API registration.
Python
The python-coinmarketcap library is a popular community-maintained option for Python developers. It can be installed using pip, Python's package installer:
pip install python-coinmarketcap
After installation, you will need to configure your API key, often by passing it as an argument during client initialization or setting it as an environment variable.
JavaScript (Node.js)
For JavaScript environments like Node.js, the coinmarketcap-api-v2 package is commonly used. Install it via npm, the Node.js package manager:
npm install coinmarketcap-api-v2
When using this library, your API key will be passed as part of the client configuration, typically as a header or a query parameter, depending on the library's implementation.
PHP
PHP developers can use the php-coinmarketcap-api library, installed via Composer, the PHP dependency manager:
composer require phatpham9/php-coinmarketcap-api
The API key is generally provided when instantiating the API client object in your PHP application.
Ruby
The coinmarketcap-ruby gem is available for Ruby projects. Install it using Bundler or directly with gem:
gem install coinmarketcap-ruby
API key configuration follows typical Ruby gem patterns, often through a configuration block or directly in the client constructor.
Java
For Java applications, a community library like coinmarketcap-java can be integrated using Maven or Gradle. You'll need to add the appropriate dependency to your pom.xml (Maven) or build.gradle (Gradle) file. Example for Maven:
<dependency>
<groupId>com.github.kunal-kushwaha</groupId>
<artifactId>coinmarketcap-java</artifactId>
<version>1.0.0</version> <!-- Check for the latest version -->
</dependency>
API key management in Java typically involves passing it to the client builder or a dedicated configuration method.
Go
Go developers can use libraries such as go-coinmarketcap. Install it using the go get command:
go get github.com/miguelmota/go-coinmarketcap
In Go, the API key is usually provided when creating a new client instance.
C#
For C# and .NET projects, CoinMarketCap.Net is a common community library. Install it using the NuGet Package Manager console:
Install-Package CoinMarketCap.Net
API key configuration in C# often involves passing it into the constructor of the API client class.
Quickstart example
This quickstart example demonstrates how to fetch the latest cryptocurrency listings using the CoinMarketCap API via a Python library. This example assumes you have installed the python-coinmarketcap library and have a valid API key from your CoinMarketCap developer account CoinMarketCap API documentation for getting started.
First, ensure your API key is available. It's recommended to store API keys securely, for example, as an environment variable, rather than hardcoding them directly in your script.
import os
from coinmarketcap import Market
# Retrieve your API key from an environment variable for security
# Replace 'YOUR_CMC_API_KEY' with the actual environment variable name if different
api_key = os.environ.get('CMC_PRO_API_KEY')
if not api_key:
print("Error: CoinMarketCap API key not found. Set the 'CMC_PRO_API_KEY' environment variable.")
exit()
# Initialize the CoinMarketCap API client
# The 'version' parameter might be required depending on the library version.
# Refer to the specific library's documentation for exact initialization.
coinmarketcap = Market(api_key)
try:
# Fetch the latest cryptocurrency listings
# Parameters like 'start', 'limit', 'convert' can be adjusted.
# For example, to get the top 10 cryptocurrencies converted to EUR:
# latest_listings = coinmarketcap.cryptocurrency_listings_latest(start=1, limit=10, convert='EUR')
latest_listings = coinmarketcap.cryptocurrency_listings_latest(start=1, limit=5, convert='USD')
print("Latest Cryptocurrency Listings (Top 5 in USD):")
for crypto in latest_listings['data']:
name = crypto['name']
symbol = crypto['symbol']
price_usd = crypto['quote']['USD']['price']
print(f" {name} ({symbol}): ${price_usd:,.2f}")
except Exception as e:
print(f"An error occurred: {e}")
# Specific error handling can be added here, e.g., for rate limits or invalid API keys.
To run this example:
- Save the code as a
.pyfile (e.g.,cmc_quickstart.py). - Set your CoinMarketCap API key as an environment variable named
CMC_PRO_API_KEY. On Linux/macOS, you can do this in your terminal:export CMC_PRO_API_KEY="YOUR_ACTUAL_API_KEY_HERE". On Windows, useset CMC_PRO_API_KEY="YOUR_ACTUAL_API_KEY_HERE"in Command Prompt or$env:CMC_PRO_API_KEY="YOUR_ACTUAL_API_KEY_HERE"in PowerShell. - Execute the script from your terminal:
python cmc_quickstart.py.
This script initializes the CoinMarketCap client with your API key and then calls the cryptocurrency_listings_latest endpoint to retrieve data for the top 5 cryptocurrencies, displaying their names, symbols, and current prices in USD. The output will be printed to your console.
Community libraries
Beyond the officially supported SDKs and examples, the CoinMarketCap developer community has created and maintained a variety of libraries across different programming languages. These community-driven projects often fill gaps, provide alternative implementations, or offer specialized functionalities not present in official resources. They are typically hosted on platforms like GitHub and distributed through language-specific package managers.
While community libraries can offer flexibility and broader language support, developers should consider several factors:
- Maintenance Status: Check the project's activity, recent commits, and issue resolution rate. An unmaintained library might not support the latest API versions or address security vulnerabilities.
- Documentation: Assess the quality and completeness of the library's documentation. Good documentation simplifies integration and troubleshooting.
- Community Support: Active communities can provide valuable assistance, but official support channels are usually limited to the API itself, not third-party libraries.
- Compatibility: Ensure the library is compatible with the specific version of the CoinMarketCap API you intend to use, as API changes can sometimes break older library versions.
- Security: Review the source code if possible, especially for libraries handling sensitive data or API keys, to ensure no unintended security risks.
Examples of community libraries include those listed in the table above for languages like PHP, Ruby, Java, Go, and C#. Developers are encouraged to explore these resources on platforms like GitHub, searching for "CoinMarketCap API" along with their preferred programming language to discover the most current and well-supported options Google's guide on engaging with open source communities.