Gemini Python API Docs | dltHub
Build a Gemini-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.
Last updated:
Gemini is a cryptocurrency exchange providing public market data and private trading/account REST APIs. The REST API base URL is https://api.gemini.com and Public endpoints are unauthenticated; private endpoints require API key HMAC headers or OAuth 2.0 access tokens..
dlt is an open-source Python library that handles authentication, pagination, and schema evolution automatically. dlthub provides AI context files that enable code assistants to generate production-ready pipelines. Install with uv pip install "dlt[workspace]" and start loading Gemini data in under 10 minutes.
What data can I load from Gemini?
Here are some of the endpoints you can load from Gemini:
| Resource | Endpoint | Method | Data selector | Description |
|---|---|---|---|---|
| symbols | /v1/symbols | GET | List available trading symbols (response: top-level array of strings) | |
| symbol_details | /v1/symbols/details/{symbol} | GET | Instrument details (response: object with fields like symbol, base_currency, min_order_size) | |
| network | /v1/network/{token} | GET | network | Networks supporting a token (response: object with token and network array) |
| pubticker | /v1/pubticker/{symbol} | GET | Current ticker for a symbol (object with bid, ask, last, volume) | |
| book | /v1/book/{symbol} | GET | bids / asks | Current order book (response: object containing bids array and asks array) |
| trades | /v1/trades/{symbol} | GET | Recent trades (response: top-level array of trade objects) | |
| pricefeed | /v1/pricefeed | GET | List of pair price objects (response: top-level array) | |
| ticker_v2 | /v2/ticker/{symbol} | GET | v2 ticker endpoint (object) | |
| candles | /v2/candles/{symbol}/{time_frame} | GET | Candles response is an array of arrays (top-level array) | |
| derivatives_candles | /v2/derivatives/candles/{symbol}/{time_frame} | GET | Derivative candles (top-level array of arrays) | |
| fxrate | /v2/fxrate/{symbol}/{timestamp} | GET | FX rate for pair and timestamp (response: object with fxPair, rate, asOf) |
How do I authenticate with the Gemini API?
Private REST endpoints use Gemini API key auth: requests include X-GEMINI-APIKEY, X-GEMINI-PAYLOAD (base64 JSON payload), and X-GEMINI-SIGNATURE (HMAC-SHA384 of payload). OAuth: use Bearer access tokens in Authorization header; examples include also sending X-GEMINI-PAYLOAD for private request payloads.
1. Get your credentials
- Log into your Gemini account (or sandbox). 2) Go to Settings -> API (API Settings). 3) Create a new API key or OAuth application; record the API Key and API Secret (or client_id/client_secret for OAuth). 4) For OAuth create app, request appropriate scopes/roles and wait for review; use client_id and client_secret to obtain tokens.
2. Add them to .dlt/secrets.toml
[sources.gemini_market_data_source] api_key = "<YOUR_API_KEY>" api_secret = "<YOUR_API_SECRET>" client_id = "<YOUR_CLIENT_ID>" client_secret = "<YOUR_CLIENT_SECRET>"
dlt reads this automatically at runtime — never hardcode tokens in your pipeline script. For production environments, see setting up credentials with dlt for environment variable and vault-based options.
How do I set up and run the pipeline?
Set up a virtual environment and install dlt:
uv venv && source .venv/bin/activate uv pip install "dlt[workspace]"
1. Install the dlt AI Workbench:
dlt ai init --agent <your-agent> # <agent>: claude | cursor | codex
This installs project rules, a secrets management skill, appropriate ignore files, and configures the dlt MCP server for your agent. Learn more →
2. Install the rest-api-pipeline toolkit:
dlt ai toolkit rest-api-pipeline install
This loads the skills and context about dlt the agent uses to build the pipeline iteratively, efficiently, and safely. The agent uses MCP tools to inspect credentials — it never needs to read your secrets.toml directly. Learn more →
3. Start LLM-assisted coding:
Use /find-source to load data from the Gemini API into DuckDB.
The rest-api-pipeline toolkit takes over from here — it reads relevant API documentation, presents you with options for which endpoints to load, and follows a structured workflow to scaffold, debug, and validate the pipeline step by step.
4. Run the pipeline:
python gemini_market_data_pipeline.py
If everything is configured correctly, you'll see output like this:
Pipeline gemini_market_data_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset gemini_market_data_data The duckdb destination used duckdb:/gemini_market_data.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs
Inspect your pipeline and data:
dlt pipeline gemini_market_data_pipeline show
This opens the Pipeline Dashboard where you can verify pipeline state, load metrics, schema (tables, columns, types), and query the loaded data directly.
Python pipeline example
This example loads symbols and trades from the Gemini API into DuckDB. It mirrors the endpoint and data selector configuration from the table above:
import dlt from dlt.sources.rest_api import RESTAPIConfig, rest_api_resources @dlt.source def gemini_market_data_source(api_key (for API-key source) or access_token (for OAuth source)=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://api.gemini.com", "auth": { "type": "api_key (HMAC header-based) and bearer (OAuth)", "for api_key flow use 'api_key' and 'api_secret' in dlt config; for bearer use 'token' (access_token)": api_key (for API-key source) or access_token (for OAuth source), }, }, "resources": [ {"name": "symbols", "endpoint": {"path": "v1/symbols"}}, {"name": "trades", "endpoint": {"path": "v1/trades/{symbol}"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="gemini_market_data_pipeline", destination="duckdb", dataset_name="gemini_market_data_data", ) load_info = pipeline.run(gemini_market_data_source()) print(load_info)
To add more endpoints, append entries from the resource table to the "resources" list using the same name, path, and data_selector pattern.
How do I query the loaded data?
Once the pipeline runs, dlt creates one table per resource. You can query with Python or SQL.
Python (pandas DataFrame):
import dlt data = dlt.pipeline("gemini_market_data_pipeline").dataset() sessions_df = data.trades.df() print(sessions_df.head())
SQL (DuckDB example):
SELECT * FROM gemini_market_data_data.trades LIMIT 10;
In a marimo or Jupyter notebook:
import dlt data = dlt.pipeline("gemini_market_data_pipeline").dataset() data.trades.df().head()
See how to explore your data in marimo Notebooks and how to query your data in Python with dataset.
What destinations can I load Gemini data to?
dlt supports loading into any of these destinations — only the destination parameter changes:
| Destination | Example value |
|---|---|
| DuckDB (local, default) | "duckdb" |
| PostgreSQL | "postgres" |
| BigQuery | "bigquery" |
| Snowflake | "snowflake" |
| Redshift | "redshift" |
| Databricks | "databricks" |
| Filesystem (S3, GCS, Azure) | "filesystem" |
Change the destination in dlt.pipeline(destination="snowflake") and add credentials in .dlt/secrets.toml. See the full destinations list.
Troubleshooting
Authentication failures
- Private endpoints return 400 for malformed auth headers or missing nonce/payload. Ensure payload JSON includes "request" set to the endpoint path and a increasing numeric "nonce"; base64-encode the JSON and sign with HMAC-SHA384 using the API secret; include X-GEMINI-APIKEY, X-GEMINI-PAYLOAD, and X-GEMINI-SIGNATURE headers. For OAuth, include Authorization: Bearer .
Rate limits and 429 errors
- Public endpoints: recommended <=120 requests/minute (≈1 req/sec). Private endpoints: recommended <=600 requests/minute (≈5 req/sec). Exceeding limits yields HTTP 429. Use exponential backoff and respect burst behavior.
Pagination and time-range limits
- Trades endpoint returns at most 500 records and is limited to seven calendar days of historical data for the public endpoint. Use 'since' timestamps (seconds or milliseconds) to page; responses are sorted by timestamp (newest first).
Ensure that the API key is valid to avoid 401 Unauthorized errors. Also, verify endpoint paths and parameters to avoid 404 Not Found errors.
Next steps
Continue your data engineering journey with the other toolkits of the dltHub AI Workbench:
data-exploration— Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.dlthub-runtime— Deploy, schedule, and monitor your pipeline in production.
dlt ai toolkit data-exploration install dlt ai toolkit dlthub-runtime install
Was this page helpful?
Community Hub
Need more dlt context for Gemini?
Request dlt skills, commands, AGENT.md files, and AI-native context.