Skip to main content

A package to export bulk data from the CoinGecko API.

Project description

CoinGecko API Wrapper

This project provides a Python wrapper for the CoinGecko API, enabling users to fetch cryptocurrency data, process it into pandas DataFrames, and upload it to AWS S3 as Parquet files. The wrapper abstracts away the complexity of asynchronous API calls and provides an easy-to-use interface for interacting with the CoinGecko API.

Table of Contents

Installation

  1. Clone the repository:

    ```bash git clone https://github.com/yourusername/coingecko-api-wrapper.git cd coingecko-api-wrapper ```

  2. Set up a virtual environment:

    ```bash python3 -m venv venv source venv/bin/activate ```

  3. Install the required dependencies:

    ```bash pip install -r requirements.txt ```

Class Structure

CoinGeckoAPI

The `CoinGeckoAPI` class is responsible for interacting directly with the CoinGecko API. It handles:

  • Making asynchronous GET requests to the API.
  • Managing rate limits using `AsyncLimiter`.
  • Fetching data from paginated endpoints.

Methods:

  • `fetch(endpoint: str, params: dict = None, retries: int = 3) -> dict`: Performs a GET request to the specified endpoint.
  • `fetch_all_pages(endpoint: str, params: dict, max_pages: int) -> list`: Fetches all pages of data asynchronously.

CoinGeckoDataProcessor

The `CoinGeckoDataProcessor` class processes raw data fetched from the CoinGecko API. It handles:

  • Merging timeseries data into a pandas DataFrame.
  • Saving DataFrames to Parquet files.

Methods:

  • `merge_timeseries_data(data: dict, coingecko_id: str) -> pd.DataFrame`: Cleans and merges timeseries data.
  • `save_to_parquet(df: pd.DataFrame, file_path: str)`: Saves a DataFrame to a Parquet file.

CoinGecko

The `CoinGecko` class is the main interface for users. It abstracts away the complexities of asynchronous calls and provides simple, synchronous methods to fetch data, process it, and upload it to S3.

Methods:

  • `get_categories() -> pd.DataFrame`: Fetches all categories from the CoinGecko API.
  • `get_coins(coins: int, category: str = None) -> pd.DataFrame`: Fetches a list of assets based on market cap.
  • `get_timeseries(coingecko_ids: list) -> pd.DataFrame`: Fetches and processes timeseries data.
  • `export_data(coins: Union[int, List[str]], export_format: str = 'df') -> pd.DataFrame`: Fetches and exports data as a DataFrame or saves it as a Parquet file.
  • `upload_to_s3(df: pd.DataFrame, aws_access_key_id: str, aws_secret_access_key: str, bucket_name: str, folder_name: str = None, file_name: str = None)`: Uploads a DataFrame to AWS S3 as a Parquet file.

Usage

Fetching Categories

```python from coingecko import CoinGecko

cg = CoinGecko(api_key="your-api-key")

Fetch and print the categories DataFrame

categories_df = cg.get_categories() print(categories_df) ```

Fetching Coins

```python from coingecko import CoinGecko

cg = CoinGecko(api_key="your-api-key")

Fetch top 100 coins by market cap

coins_df = cg.get_coins(100) print(coins_df) ```

Fetching Timeseries Data

```python from coingecko import CoinGecko

cg = CoinGecko(api_key="your-api-key")

Fetch timeseries data for a list of coin IDs

timeseries_df = cg.get_timeseries(['bitcoin', 'ethereum']) print(timeseries_df) ```

Exporting Data to Parquet

```python from coingecko import CoinGecko

cg = CoinGecko(api_key="your-api-key")

Export data to a Parquet file

cg.export_data(coins=100, export_format='parquet') ```

Uploading Data to S3

```python from coingecko import CoinGecko

cg = CoinGecko(api_key="your-api-key")

Fetch and upload coins data to S3

coins_df = cg.get_coins(100) cg.upload_to_s3( df=coins_df, aws_access_key_id="your-aws-access-key-id", aws_secret_access_key="your-aws-secret-access-key", bucket_name="your-s3-bucket-name", folder_name="your-folder-name", file_name="your-file-name.parquet" ) ```

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_exporter-0.3.1.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

coingecko_exporter-0.3.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file coingecko_exporter-0.3.1.tar.gz.

File metadata

  • Download URL: coingecko_exporter-0.3.1.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for coingecko_exporter-0.3.1.tar.gz
Algorithm Hash digest
SHA256 7edaeb46d8dd4fef7288da95dac9a6195b77c0b9b7dd65814e6a261bf37a0783
MD5 971831f12e3ef035f701ee56e00e9c17
BLAKE2b-256 c967d40ff3ca49c20daf6e8a63d7ab9d2d4a6dac071288e5dc2dce930f6f90c0

See more details on using hashes here.

File details

Details for the file coingecko_exporter-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for coingecko_exporter-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 24f0eab9814f2768ec19358c7137f94f2a011b6f9f354e7afaf2008e600b331e
MD5 cb8ab5cb5e15b1828b9a05149cb4f76a
BLAKE2b-256 fe9bc929b2bceeb8155eeca04e00f4178d1a7826714988c367aad727580dd780

See more details on using hashes here.

Supported by

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