G2 Python API Docs | dltHub
Build a G2-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.
Last updated:
G2 is a platform that provides programmatic access to product, category, review, and related marketplace data via a REST API. The REST API base URL is https://data.g2.com and all requests require a token provided in the Authorization header (Token token=...).
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 G2 data in under 10 minutes.
What data can I load from G2?
Here are some of the endpoints you can load from G2:
| Resource | Endpoint | Method | Data selector | Description |
|---|---|---|---|---|
| products | api/v1/products | GET | data | List products with attributes (name, slug, ratings, review_count, etc.) |
| products_show | api/v1/products/:id | GET | data | Get single product details (attributes & relationships) |
| survey_responses | api/v1/survey-responses | GET | data | List reviews/survey responses (use filters like filter[product_id]) |
| survey_responses_show | api/v1/survey-responses/:id | GET | data | Get single survey response / review by id |
| categories | api/v1/categories | GET | data | List categories (category metadata, slug, name) |
| questions | api/v1/questions | GET | data | List questions used in surveys |
| answers | api/v1/answers | GET | data | List answers (survey question answers) |
| resource_subscriptions | api/v1/resource-subscriptions | GET | data | List RESThook subscriptions (webhook configs) |
| syndication_products | api/2018-01-01/syndication/products | GET | data | Syndication product list (alternate syndication API) |
| syndication_reviews | api/2018-01-01/syndication/reviews | GET | data | Syndication reviews list (use filter[product_id]) |
How do I authenticate with the G2 API?
Requests must include Authorization: Token token=<API_TOKEN> and typically Content-Type: application/vnd.api+json. API tokens can also be created in the Developer Portal (Access Tokens) or via registered OAuth apps for OAuth flows.
1. Get your credentials
- Sign in or create an account in the G2 Developer Portal (https://my.g2.com/developers). 2) Open Access Tokens or OAuth Apps tab. 3) For a simple API token, go to Access Tokens → Generate Token, name it, choose Resource Owner (User or Organization), set endpoint permissions, and Generate. 4) Copy the token (visible via Eye icon). For OAuth, register an OAuth app in OAuth Apps, set redirect URL and permissions, save, then use the client_id/secret to perform the OAuth flow obtaining access tokens.
2. Add them to .dlt/secrets.toml
[sources.g2_source] api_token = "your_api_token_here"
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 G2 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 g2_pipeline.py
If everything is configured correctly, you'll see output like this:
Pipeline g2_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset g2_data The duckdb destination used duckdb:/g2.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs
Inspect your pipeline and data:
dlt pipeline g2_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 products and survey_responses from the G2 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 g2_source(api_token=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://data.g2.com", "auth": { "type": "api_key", "api_token": api_token, }, }, "resources": [ {"name": "products", "endpoint": {"path": "api/v1/products", "data_selector": "data"}}, {"name": "survey_responses", "endpoint": {"path": "api/v1/survey-responses", "data_selector": "data"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="g2_pipeline", destination="duckdb", dataset_name="g2_data", ) load_info = pipeline.run(g2_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("g2_pipeline").dataset() sessions_df = data.products.df() print(sessions_df.head())
SQL (DuckDB example):
SELECT * FROM g2_data.products LIMIT 10;
In a marimo or Jupyter notebook:
import dlt data = dlt.pipeline("g2_pipeline").dataset() data.products.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 G2 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
If you receive 401 Unauthorized or 403 Forbidden: verify you included Authorization: Token token=<API_TOKEN> exactly, confirm the token has the proper permissions in Developer Portal (Access Tokens or OAuth app scopes), and ensure the token has not expired (Access Tokens expire after one year). For OAuth flows ensure redirect URL and scopes match the registered OAuth app.
Rate limits
G2 enforces a global rate limit (documented as 100 requests per second). Exceeding the limit returns 429 Too Many Requests and may block access for ~60 seconds. Implement client-side throttling, exponential backoff, and respect Retry-After headers if present.
Pagination and selectors
Collection endpoints return results under the top-level "data" key and include meta and links objects for pagination. Use page[size] (default 10, max typically 100) and page[number] to page through results. Check meta.record_count and links.next for termination.
Common errors
400 Bad Request – malformed request or invalid filters. 401 Unauthorized – missing/invalid token. 402 Payment Required – subscription issues. 403 Forbidden – not permitted for your token. 404 Not Found – resource does not exist. 414 Request URI too long – too many filters. 422 Unprocessable Entity – invalid request. 429 Too Many Requests – rate limited. 500/503 – server errors; retry with backoff.
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 G2?
Request dlt skills, commands, AGENT.md files, and AI-native context.