An Extract-Load (EL) pipeline that fetches cryptocurrency market data from CoinMarketCap's API and stores it in a DuckDB database using dlt.
- Extracts market data for cryptocurrencies (currently set to BTC, ETH, and LTC)
- Easily configurable to track any cryptocurrency available on CoinMarketCap
- Loads data directly into DuckDB
- Includes error handling and logging
- Uses Python best practices
- Manages API keys securely with dlt secrets
- Python (3.9+)
- dlt
- DuckDB
- CoinMarketCap API
The pipeline collects these metrics for each cryptocurrency:
- Current price (USD)
- 24-hour trading volume
- Market capitalization
- Last update timestamp
- Python 3.9 or higher
- CoinMarketCap API key (Get it here)
-
Clone the repository:
git clone https://github.com/victor-antoniassi/coinmarketcap_api_to_duckdb.git cd coinmarketcap_api_to_duckdb
-
Install dependencies:
pip install -r requirements.txt
-
Set up API credentials:
- Create a
.dlt/secrets.toml
file - Add your API key:
coinmarketcap.api_key = "your-api-key-here" destination.duckdb_path = "path/to/your/database.db"
- Create a
-
Run the pipeline as is:
python dlt_to_duckdb.py
-
Or modify the cryptocurrency list in
dlt_to_duckdb.py
:response = client.get( "/cryptocurrency/quotes/latest", params={ "symbol": "BTC,ETH,LTC", # Add or change cryptocurrencies here "convert": "USD" } )
The script will:
- Connect to CoinMarketCap API
- Get current market data
- Save the data to DuckDB
- Show the saved data
coinmarketcap_api_to_duckdb/
├── .dlt/
│ └── secrets.toml # API credentials
├── dlt_to_duckdb.py # Main script
├── requirements.txt # Dependencies
└── README.md # Documentation
- Auth: Uses API key from
.dlt/secrets.toml
- Extract: Gets cryptocurrency data from API
- Validate: Checks data quality
- Load: Saves to DuckDB
- Verify: Runs a test query
Last updated: November 2024