Skip to content

feat(integrations): Add Integrations API client - #2813

Draft
vikramlc-cognite wants to merge 6 commits into
masterfrom
EDG-827-add-integrations-api-support
Draft

feat(integrations): Add Integrations API client#2813
vikramlc-cognite wants to merge 6 commits into
masterfrom
EDG-827-add-integrations-api-support

Conversation

@vikramlc-cognite

Copy link
Copy Markdown

Summary

Adds a new client.integrations module (Integrations, Task history/sync, Errors, Config revisions, Actions) so SDK consumers can manage the new alpha/public-preview Integrations API, modeled on the existing simulators module.

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that changes existing behavior)
  • Refactor (no functional change)
  • Documentation update
  • Chore / tooling / CI

What changed

  • New cognite/client/data_classes/integrations/ package: Integration/IntegrationWrite/IntegrationUpdate (+ lists), Action/ActionWrite (the new Actions sub-resource), ConfigRevision/ConfigRevisionWrite/ConfigRevisionMetadata, TaskHistory/SyncResult, IntegrationError.
  • New cognite/client/_api/integrations/ package: IntegrationsAPI (list/create/retrieve/update/delete) composing four sub-APIs — .tasks (task history + incremental /sync), .errors, .config (versioned config revisions), .actions (create/list/retrieve/cancel).
  • cognite/client/_sync_api/integrations/ generated via the repo's sync codegen script — not hand-written.
  • Wired client.integrations into both AsyncCogniteClient and the sync CogniteClient, plus cognite/client/testing.py's CogniteClientMock/AsyncCogniteClientMock.
  • cognite/client/utils/_url.py: registered integrations, integrations/config, integrations/actions, and integrations/actions/cancel as non-idempotent POST paths (create/config-create/action-create/cancel aren't safe to auto-retry); added matching cases to TestRetryableEndpoints.
  • Every client.integrations* call sends the mandatory cdf-version: alpha header and raises the SDK's alpha FeaturePreviewWarning.
  • Scope excludes startup, checkin, and extpipes/runs — all three are marked ifdef: internal in the service contract (extractor-only protocol / legacy back-compat, already covered by ExtractionPipelinesAPI).
  • New unit tests: tests/tests_unit/test_api/test_integrations/ (26 tests, mocked HTTP) and tests/tests_unit/test_data_classes/test_integrations.py (load/dump round-trips, incl. all three IntegrationUpdate patch shapes).

Why it changed

  • Related issue: EDG-827
  • Related docs / discussion: cognitedata/service-contracts PR #3378 (wire schema + public/internal marking); docs.cognite.com Integrations concept pages (20230101-alpha, "public preview"); odin repo (ground-truth route/DTO source, confirms mandatory cdf-version: alpha header)
  • The Integrations API replaces the legacy Extraction Pipelines API for extractor registration, task/error history, versioned config, and (new) remote Actions. It's live and usable by customers today but had no Python SDK support.

What to focus on during review

  • Maturity handling: whole API is ifdef: alpha in the contract (not GA like simulators), so it follows the LimitsAPI pattern (api_maturity="alpha" + self._alpha_version_header() on every call) rather than the GA simulators pattern — worth double-checking this is the right precedent.
  • Identifiers are external-id-only everywhere (no internal numeric id in this API, unlike simulators) — ExternalIDTransformerMixin used throughout instead of IdTransformerMixin.
  • IntegrationConfigAPI.list() hits a GET endpoint that accepts cursor/limit but its response has no nextCursor — implemented as a single call with a docstring note, not _list/_list_generator.
  • IntegrationActionsAPI.create()/.cancel() are hand-rolled _post calls (not the generic _create_multiple/_delete_multiple helpers) because the integration's external ID is a query param, not part of the item body — includes manual chunking (20/100 items) since the generic helpers' automatic chunking isn't available here.
  • The non-idempotent POST path classification in _url.py — I marked create/config-create/action-create/action-cancel as non-retryable; update/retrieve/list/config-retrieve were left retryable. Worth a sanity check against actual server semantics.
  • cognite/client/_sync_api/integrations/ and _sync_cognite_client.py are generated — please don't review them line-by-line, just confirm scripts/sync_client_codegen/main.py verify passes (it does).

Test evidence

  • pytest tests/tests_unit/test_api/test_integrations/ tests/tests_unit/test_data_classes/test_integrations.py -v → 26 passed.
  • pytest tests/tests_unit/ (with pandas/numpy extras installed) → 6664 passed, 8 pre-existing failures unrelated to this change (missing geopandas/sympy), 0 regressions (verified via git stash A/B comparison against the base branch).
  • mypy clean across all new/changed files (_api/integrations, data_classes/integrations, _cognite_client.py, _sync_cognite_client.py, _sync_api/integrations, testing.py, utils/_url.py).
  • ruff check / ruff format clean.
  • python scripts/sync_client_codegen/main.py verify → up to date.
  • Manual smoke test: instantiated a CogniteClient and confirmed client.integrations, .tasks, .errors, .config, .actions all resolve to the expected sync API classes.

Risks and unknowns

  • The upstream API is alpha/public-preview and may still change (the Actions resource is the newest, most-recently-added part of the contract) — some field names/shapes could shift before GA.
  • No live integration tests yet (deliberate, per scope discussion) — only mocked unit tests. Should be added once a test CDF project with Integrations enabled is available.
  • TaskHistory includes warning_count/fatal_count/sources/targets fields observed in the odin service's actual DTOs but not fully detailed in the service-contracts snapshot reviewed — flagging in case the contract is later tightened.
  • Top-level data_classes export follows the simulators precedent of not re-exporting from cognite/client/data_classes/__init__.py (submodule-only import) — intentional, but worth confirming this is still the desired convention for alpha features.

Rollout and rollback

  • Purely additive — no migrations, no config changes, no existing behavior altered. Safe to revert by reverting this PR.
  • No feature flag; gated by the SDK's standard FeaturePreviewWarning/global_config.silence_feature_preview_warnings mechanism.

Checklist

  • Self-reviewed the diff
  • Tests added or updated (or N/A with reason)
  • Docs updated (or N/A) — Sphinx API docs are generated from docstrings already included; no separate hand-written docs page added
  • No secrets, credentials, or PII committed
  • Breaking changes called out above and communicated to affected teams — N/A, purely additive

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.54621% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.23%. Comparing base (298b46c) to head (c7a3af1).

Files with missing lines Patch % Lines
...e/client/data_classes/integrations/integrations.py 96.00% 4 Missing ⚠️
cognite/client/_api/integrations/__init__.py 95.52% 3 Missing ⚠️
cognite/client/_api/integrations/actions.py 96.29% 2 Missing ⚠️
cognite/client/_basic_api_client.py 71.42% 2 Missing ⚠️
cognite/client/_api/integrations/config.py 96.15% 1 Missing ⚠️
cognite/client/_sync_api/integrations/__init__.py 98.11% 1 Missing ⚠️
...ognite/client/data_classes/integrations/actions.py 97.43% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2813      +/-   ##
==========================================
+ Coverage   93.15%   93.23%   +0.07%     
==========================================
  Files         516      539      +23     
  Lines       53665    54628     +963     
==========================================
+ Hits        49993    50932     +939     
- Misses       3672     3696      +24     
Files with missing lines Coverage Δ
cognite/client/_api/integrations/errors.py 100.00% <100.00%> (ø)
cognite/client/_api/integrations/tasks.py 100.00% <100.00%> (ø)
cognite/client/_cognite_client.py 96.01% <100.00%> (+0.18%) ⬆️
cognite/client/_sync_api/integrations/actions.py 100.00% <100.00%> (ø)
cognite/client/_sync_api/integrations/config.py 100.00% <100.00%> (ø)
cognite/client/_sync_api/integrations/errors.py 100.00% <100.00%> (ø)
cognite/client/_sync_api/integrations/tasks.py 100.00% <100.00%> (ø)
cognite/client/_sync_cognite_client.py 89.09% <100.00%> (+0.20%) ⬆️
...gnite/client/data_classes/integrations/__init__.py 100.00% <100.00%> (ø)
...ognite/client/data_classes/integrations/checkin.py 100.00% <100.00%> (ø)
... and 19 more

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vikramlc-cognite

Copy link
Copy Markdown
Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the new Integrations API to the Cognite Python SDK, including asynchronous and synchronous clients, data classes, and comprehensive unit tests. The review feedback focuses on improving robustness and type safety by safely handling potential null values in JSON deserialization and adding client-side validation to raise ValueErrors early for invalid API parameter combinations.

Comment thread cognite/client/data_classes/integrations/integrations.py Outdated
Comment thread cognite/client/data_classes/integrations/integrations.py Outdated
Comment thread cognite/client/data_classes/integrations/tasks.py Outdated
Comment thread cognite/client/_api/integrations/tasks.py
Comment thread cognite/client/_api/integrations/errors.py
Comment thread cognite/client/_api/integrations/tasks.py
@vikramlc-cognite vikramlc-cognite self-assigned this Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants