Cognite Data Fusion Python API Docs | dltHub
Build a Cognite Data Fusion-to-database pipeline in Python using dlt with AI harness support for Claude Code, Cursor, and Codex.
Last updated:
Cognite Data Fusion is a cloud data platform exposing a RESTful API for managing industrial data resources such as assets, files, events, and time series. The REST API base URL is https://api.cognitedata.com/api/v1/projects/{project} and every request requires an OAuth 2.0/OIDC JWT access token sent as a Bearer token in the Authorization header.
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 add "dlt[hub]" and start loading Cognite Data Fusion data in under 10 minutes.
What data can I load from Cognite Data Fusion?
Here are some of the endpoints you can load from Cognite Data Fusion:
| Resource | Endpoint | Method | Data selector | Description |
|---|---|---|---|---|
| assets | assets | GET | items | List assets; supports limit (max 1000), cursor/nextCursor pagination, and lastUpdatedTime min/max range filter for incremental loads; records have id and lastUpdatedTime |
| events | events | GET | items | List events; supports limit (1..1000, default 100), cursor/nextCursor pagination, and lastUpdatedTime min/max range filter; records have id and lastUpdatedTime |
| timeseries | timeseries | GET | items | List time series; supports limit, cursor/nextCursor pagination, and lastUpdatedTime min/max range filter; records have id and lastUpdatedTime |
| files | files | GET | items | List file metadata; supports limit, cursor/nextCursor pagination, and lastUpdatedTime min/max range filter; records have id and lastUpdatedTime |
| datasets | datasets | GET | items | List data sets; response is DataSetListWithCursor with items array and optional nextCursor |
| raw_cursors | raw/dbs/{dbName}/tables/{tableName}/cursors | GET | items | Retrieve cursors for parallel incremental reads of Raw rows based on minLastUpdatedTime/maxLastUpdatedTime (epoch ms); returns array of cursor strings in items |
How do I authenticate with the Cognite Data Fusion API?
CDF authenticates via standard OAuth 2.0 / OIDC JSON Web Tokens issued by an identity provider (e.g. Microsoft Entra ID), sent with every API request in the Authorization: Bearer header. The project identifier is part of the URL path rather than a header, so no additional required headers are specified.
1. Get your credentials
Cognite Data Fusion authenticates via OAuth 2.0 / OpenID Connect (API keys are deprecated and no longer supported for new setups). To obtain credentials: 1) Sign in to the CDF dashboard at https://fusion.cognite.com, enter your organization name, your work account credentials, and select your CDF project. 2) In your identity provider (most commonly Microsoft Entra ID, or Amazon Cognito), register an application (service principal / machine-to-machine app) for your integration and create a client secret — these IdP credentials (client ID, client secret, and tenant ID for Entra ID) are created and managed in the IdP, not in CDF. 3) In CDF, create a service account and add it to a CDF group with the capabilities your integration needs (e.g. timeseries
, assets), and link the IdP app to that service account/group. 4) Use the client credentials flow to get an access token from the IdP token URL (e.g. https://login.microsoftonline.com/{tenant_id}/oauth2/v2.0/token) with scope https://{cluster}.cognitedata.com/.default, and send it as 'Authorization: Bearer ' to https://{cluster}.cognitedata.com/api/v1/projects/{project}/... For the public Open Industrial Data sample project, you can instead sign up at Cognite Hub (hub.cognite.com) and get the client ID/secret from the Open Industrial Data credentials widget (cluster 'api', project 'publicdata').2. Add them to .dlt/secrets.toml
[sources.cognite_data_fusion_source] api_key = "your_api_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 init uv add "dlt[hub]"
1. Install the dlt AI harness:
uv run dlthub 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:
uv run dlthub ai toolkit install rest-api-pipeline
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 Cognite Data Fusion 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:
uv run python cognite_data_fusion_pipeline.py
If everything is configured correctly, you'll see output like this:
Pipeline cognite_data_fusion_pipeline load step completed in 0.26 seconds 1 load package(s) were loaded to destination duckdb and into dataset cognite_data_fusion_data The duckdb destination used duckdb:/cognite_data_fusion.duckdb location to store data Load package 1749667187.541553 is LOADED and contains no failed jobs
Inspect your pipeline and data:
uv run dlthub 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 assets and timeseries from the Cognite Data Fusion 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 cognite_data_fusion_source(api_key=dlt.secrets.value): config: RESTAPIConfig = { "client": { "base_url": "https://api.cognitedata.com/api/v1/projects/{project}", "auth": {"type": "bearer", "token": api_key}, }, "resources": [ {"name": "assets", "endpoint": {"path": "assets", "data_selector": "items"}}, {"name": "events", "endpoint": {"path": "events", "data_selector": "items"}} ], } yield from rest_api_resources(config) def get_data() -> None: pipeline = dlt.pipeline( pipeline_name="cognite_data_fusion_pipeline", destination="duckdb", dataset_name="cognite_data_fusion_data", ) load_info = pipeline.run(cognite_data_fusion_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("cognite_data_fusion_pipeline").dataset() sessions_df = data.assets.df() print(sessions_df.head())
SQL (DuckDB example):
SELECT * FROM cognite_data_fusion_data.assets LIMIT 10;
In a marimo or Jupyter notebook:
import dlt data = dlt.pipeline("cognite_data_fusion_pipeline").dataset() data.assets.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 Cognite Data Fusion 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.
Next steps
Continue your data engineering journey with the other toolkits of the dltHub AI harness:
data-exploration— Build custom notebooks, charts, and dashboards for deeper analysis with marimo notebooks.dlthub-platform— Deploy, schedule, and monitor your pipeline in production.
uv run dlthub ai toolkit install data-exploration uv run dlthub ai toolkit install dlthub-platform
Was this page helpful?
Community Hub
Need more dlt context for Cognite Data Fusion?
Request dlt skills, commands, AGENT.md files, and AI-native context.