Datadog Python API Docs | dltHub

Build a Datadog-to-database pipeline in Python using dlt with AI Workbench support for Claude Code, Cursor, and Codex.

Last updated:

Datadog is a monitoring and observability platform that collects, visualizes, and correlates metrics, logs, events, and traces via a REST API. The REST API base URL is https://api.datadoghq.com (note: regional sites may vary, e.g. api.datadoghq.eu; Datadog uses 'site' and 'domain' parameters for region-aware APIs) and requests require an API key (api_key) and an application key (app_key) OR OAuth Bearer token for integrations..

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 Datadog data in under 10 minutes.


What data can I load from Datadog?

Here are some of the endpoints you can load from Datadog:

ResourceEndpointMethodData selectorDescription
metrics/api/v1/metrics (and v2 equivalents under /api/v2/metrics)GETdata (often top-level 'data' for v2; some v1 endpoints return top-level objects)Query and list metrics, tag cardinality, and related metric metadata
logs/api/v2/logs/events/search (or /api/v1/logs-queries)GETdata (response array located in 'data')Search and list logs matching a query (paginated)
events/api/v1/events (search) and /api/v2/eventsGETevents (v1) or data (v2)List events matching search criteria (paginated)
dashboards/api/v1/dashboard/{dashboard_id} and /api/v1/dashboardsGET(single dashboard object) or data/included for v2Get dashboard(s) and full widget definitions
monitors/api/v1/monitor and /api/v2/monitorsGET(v1 returns top-level arrays/objects; v2 uses 'data')List monitors and monitor details
hosts/api/v1/hostsGEThost_list or as documented (responses vary)List hosts reporting to Datadog
users/api/v2/usersGETdataList users in an organization

How do I authenticate with the Datadog API?

Datadog supports two primary auth mechanisms: (1) API + Application keys: include headers 'DD-API-KEY: <api_key>' and 'DD-APPLICATION-KEY: <app_key>' for most API calls; (2) OAuth2 access tokens for OAuth apps: include 'Authorization: Bearer <access_token>'.

1. Get your credentials

  1. Sign in to Datadog and go to Integrations -> APIs (or Organization settings -> API Keys). 2) Create an API key (used to submit and query data). 3) Create an Application key (scoped to a user; used for management/read operations). 4) For OAuth integrations, create an OAuth app and follow Datadog's OAuth flow to obtain an access_token and required scopes.

2. Add them to .dlt/secrets.toml

[sources.datadog_source] api_key = "your_api_key_here" app_key = "your_application_key_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 Datadog 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 datadog_pipeline.py

If everything is configured correctly, you'll see output like this:

Pipeline datadog_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset datadog_data The duckdb destination used duckdb:/datadog.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs

Inspect your pipeline and data:

dlt pipeline datadog_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 logs and metrics from the Datadog 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 datadog_source(api_key=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://api.datadoghq.com (note: regional sites may vary, e.g. api.datadoghq.eu; Datadog uses 'site' and 'domain' parameters for region-aware APIs)", "auth": { "type": "api_key", "api_key": api_key, }, }, "resources": [ {"name": "logs", "endpoint": {"path": "api/v2/logs/events/search", "data_selector": "data"}}, {"name": "metrics", "endpoint": {"path": "api/v2/metrics", "data_selector": "data"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="datadog_pipeline", destination="duckdb", dataset_name="datadog_data", ) load_info = pipeline.run(datadog_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("datadog_pipeline").dataset() sessions_df = data.logs.df() print(sessions_df.head())

SQL (DuckDB example):

SELECT * FROM datadog_data.logs LIMIT 10;

In a marimo or Jupyter notebook:

import dlt data = dlt.pipeline("datadog_pipeline").dataset() data.logs.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 Datadog data to?

dlt supports loading into any of these destinations — only the destination parameter changes:

DestinationExample 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 403 or 'Missing required attribute' errors, verify you sent DD-API-KEY and DD-APPLICATION-KEY headers or 'Authorization: Bearer ' for OAuth. Application keys are user-scoped and needed for read/management endpoints; API keys are required for data submission.

Rate limits / Too many requests (429)

Datadog enforces rate limits per endpoint and per organization. On 429 responses, back off and retry with exponential backoff. Inspect response headers for remaining quotas when available.

Pagination quirks

Many list endpoints (logs, events, metrics v2) return paginated results and place records under a 'data' array (v2 JSON:API style). Use provided pagination tokens/links to fetch subsequent pages. Some v1 endpoints return top-level arrays or endpoint-specific keys (e.g., 'events' for v1 events).

Common API errors (examples):

  • 400 Bad Request — response body: {"errors": ["Bad Request"]} or JSON:API error objects with 'errors' array and objects containing 'detail' and 'status'.
  • 403 Forbidden — missing/insufficient keys or scopes; response contains errors array.
  • 404 Not Found — requested resource missing; response contains errors array.
  • 429 Too Many Requests — rate limit exceeded.

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 Datadog?

Request dlt skills, commands, AGENT.md files, and AI-native context.