cognite-toolkit 0.7.45__py3-none-any.whl → 0.7.47__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cognite_toolkit/_cdf_tk/apps/_download_app.py +1 -1
- cognite_toolkit/_cdf_tk/apps/_dump_app.py +1 -1
- cognite_toolkit/_cdf_tk/builders/_raw.py +1 -1
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +19 -3
- cognite_toolkit/_cdf_tk/client/api/agents.py +107 -0
- cognite_toolkit/_cdf_tk/client/api/annotations.py +129 -0
- cognite_toolkit/_cdf_tk/client/api/assets.py +30 -18
- cognite_toolkit/_cdf_tk/client/api/containers.py +132 -0
- cognite_toolkit/_cdf_tk/client/api/data_models.py +137 -0
- cognite_toolkit/_cdf_tk/client/api/datasets.py +141 -0
- cognite_toolkit/_cdf_tk/client/api/events.py +31 -17
- cognite_toolkit/_cdf_tk/client/api/extraction_pipelines.py +148 -0
- cognite_toolkit/_cdf_tk/client/api/filemetadata.py +42 -16
- cognite_toolkit/_cdf_tk/client/api/function_schedules.py +115 -0
- cognite_toolkit/_cdf_tk/client/api/functions.py +113 -0
- cognite_toolkit/_cdf_tk/client/api/graphql_data_models.py +167 -0
- cognite_toolkit/_cdf_tk/client/api/groups.py +121 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_destinations.py +131 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_jobs.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_mappings.py +129 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractor_sources.py +136 -0
- cognite_toolkit/_cdf_tk/client/api/hosted_extractors.py +23 -0
- cognite_toolkit/_cdf_tk/client/api/infield.py +7 -7
- cognite_toolkit/_cdf_tk/client/api/labels.py +125 -0
- cognite_toolkit/_cdf_tk/client/api/legacy/canvas.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/legacy/charts.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_data_modeling.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_files.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_raw.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/extended_timeseries.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/legacy/location_filters.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/capabilities.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/data_postprocessing.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/frames.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/locations.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/maps.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/robots.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/search_config.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/migration.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/project.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/raw.py +38 -8
- cognite_toolkit/_cdf_tk/client/api/relationships.py +133 -0
- cognite_toolkit/_cdf_tk/client/api/security_categories.py +94 -0
- cognite_toolkit/_cdf_tk/client/api/sequences.py +133 -0
- cognite_toolkit/_cdf_tk/client/api/simulator_models.py +32 -6
- cognite_toolkit/_cdf_tk/client/api/spaces.py +117 -0
- cognite_toolkit/_cdf_tk/client/api/streams.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/three_d.py +11 -11
- cognite_toolkit/_cdf_tk/client/api/timeseries.py +31 -17
- cognite_toolkit/_cdf_tk/client/api/token.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/transformations.py +146 -0
- cognite_toolkit/_cdf_tk/client/api/views.py +139 -0
- cognite_toolkit/_cdf_tk/client/api/workflow_triggers.py +128 -0
- cognite_toolkit/_cdf_tk/client/api/workflow_versions.py +138 -0
- cognite_toolkit/_cdf_tk/client/api/workflows.py +119 -0
- cognite_toolkit/_cdf_tk/client/cdf_client/api.py +44 -40
- cognite_toolkit/_cdf_tk/client/cdf_client/responses.py +11 -0
- cognite_toolkit/_cdf_tk/client/http_client/_data_classes.py +10 -0
- cognite_toolkit/_cdf_tk/client/http_client/_data_classes2.py +5 -7
- cognite_toolkit/_cdf_tk/client/http_client/_exception.py +10 -1
- cognite_toolkit/_cdf_tk/client/request_classes/base.py +19 -0
- cognite_toolkit/_cdf_tk/client/request_classes/filters.py +69 -0
- cognite_toolkit/_cdf_tk/client/request_classes/graphql.py +28 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/agent.py +9 -3
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/annotation.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/asset.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_constraints.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_container.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_data_model.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_data_types.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_indexes.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_instance.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_references.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_space.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_view.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/_view_property.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/dataset.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/event.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/extraction_pipeline.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/filemetadata.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/function.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/function_schedule.py +65 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/graphql_data_model.py +40 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/__init__.py +187 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/_constants.py +2 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/acls.py +653 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/capability.py +56 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/group.py +63 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/group/scopes.py +166 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_destination.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_job.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_mapping.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/_auth.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/_base.py +2 -2
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/_certificate.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/_eventhub.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/_kafka.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/_mqtt.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/_rest.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/identifiers.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/label.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/legacy/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/canvas.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/charts.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/location_filter.py +77 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/raw.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/relationship.py +49 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/__init__.py +37 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_capability.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_common.py +34 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_data_post_processing.py +49 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_frame.py +46 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_location.py +36 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_map.py +60 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_robot.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/search_config_resource.py +54 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/securitycategory.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/sequence.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/sequence_rows.py +56 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/simulator_model.py +1 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/streamlit_.py +71 -0
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/streams.py +6 -5
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/timeseries.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/transformation.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/workflow.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/workflow_trigger.py +1 -1
- cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/workflow_version.py +1 -1
- cognite_toolkit/_cdf_tk/client/testing.py +20 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +5 -5
- cognite_toolkit/_cdf_tk/commands/_migrate/creators.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +6 -6
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +6 -6
- cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +8 -8
- cognite_toolkit/_cdf_tk/commands/_profile.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_purge.py +1 -1
- cognite_toolkit/_cdf_tk/commands/build_cmd.py +1 -1
- cognite_toolkit/_cdf_tk/commands/dump_resource.py +4 -4
- cognite_toolkit/_cdf_tk/commands/run.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +3 -3
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +2 -2
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +11 -27
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +4 -4
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +7 -14
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +2 -2
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py +6 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py +1 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/simulators.py +6 -3
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +2 -2
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +6 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py +1 -1
- cognite_toolkit/_cdf_tk/resource_classes/capabilities.py +6 -0
- cognite_toolkit/_cdf_tk/resource_classes/search_config.py +1 -1
- cognite_toolkit/_cdf_tk/storageio/_applications.py +3 -3
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +21 -27
- cognite_toolkit/_cdf_tk/storageio/_file_content.py +2 -2
- cognite_toolkit/_cdf_tk/storageio/_instances.py +1 -1
- cognite_toolkit/_cdf_tk/utils/cdf.py +1 -1
- cognite_toolkit/_cdf_tk/utils/interactive_select.py +5 -5
- cognite_toolkit/_cdf_tk/utils/useful_types2.py +3 -3
- cognite_toolkit/_repo_files/GitHub/.github/workflows/deploy.yaml +1 -1
- cognite_toolkit/_repo_files/GitHub/.github/workflows/dry-run.yaml +1 -1
- cognite_toolkit/_resources/cdf.toml +1 -1
- cognite_toolkit/_version.py +1 -1
- {cognite_toolkit-0.7.45.dist-info → cognite_toolkit-0.7.47.dist-info}/METADATA +3 -3
- {cognite_toolkit-0.7.45.dist-info → cognite_toolkit-0.7.47.dist-info}/RECORD +203 -152
- {cognite_toolkit-0.7.45.dist-info → cognite_toolkit-0.7.47.dist-info}/WHEEL +2 -2
- /cognite_toolkit/_cdf_tk/client/{data_classes → request_classes}/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes/legacy → resource_classes}/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/base.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/capabilities.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/charts_data.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/data_modeling/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/hosted_extractor_source/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/infield.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/instance_api.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/apm_config_v1.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extendable_cognite_file.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extended_filemetadata.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extended_filemetdata.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/extended_timeseries.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/functions.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/graphql_data_models.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/instances.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/location_filters.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/migration.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/pending_instances_ids.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/project.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/raw.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/robotics.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/search_config.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/sequences.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/legacy/streamlit_.py +0 -0
- /cognite_toolkit/_cdf_tk/client/{data_classes → resource_classes}/three_d.py +0 -0
- {cognite_toolkit-0.7.45.dist-info → cognite_toolkit-0.7.47.dist-info}/entry_points.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from collections.abc import Sequence
|
|
1
|
+
from collections.abc import Iterable, Sequence
|
|
2
2
|
|
|
3
3
|
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, Endpoint, PagedResponse, ResponseItems
|
|
4
|
-
from cognite_toolkit._cdf_tk.client.data_classes.raw import RAWDatabase, RAWTable
|
|
5
4
|
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.raw import RAWDatabase, RAWTable
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class RawDatabasesAPI(CDFResourceAPI[RAWDatabase, RAWDatabase, RAWDatabase]):
|
|
@@ -21,7 +21,7 @@ class RawDatabasesAPI(CDFResourceAPI[RAWDatabase, RAWDatabase, RAWDatabase]):
|
|
|
21
21
|
},
|
|
22
22
|
)
|
|
23
23
|
|
|
24
|
-
def
|
|
24
|
+
def _validate_page_response(self, response: SuccessResponse2 | ItemsSuccessResponse2) -> PagedResponse[RAWDatabase]:
|
|
25
25
|
return PagedResponse[RAWDatabase].model_validate_json(response.body)
|
|
26
26
|
|
|
27
27
|
def _reference_response(self, response: SuccessResponse2) -> ResponseItems[RAWDatabase]:
|
|
@@ -47,7 +47,7 @@ class RawDatabasesAPI(CDFResourceAPI[RAWDatabase, RAWDatabase, RAWDatabase]):
|
|
|
47
47
|
"""
|
|
48
48
|
self._request_no_response(list(items), "delete", extra_body={"recursive": recursive})
|
|
49
49
|
|
|
50
|
-
def
|
|
50
|
+
def paginate(
|
|
51
51
|
self,
|
|
52
52
|
limit: int = 100,
|
|
53
53
|
cursor: str | None = None,
|
|
@@ -61,7 +61,21 @@ class RawDatabasesAPI(CDFResourceAPI[RAWDatabase, RAWDatabase, RAWDatabase]):
|
|
|
61
61
|
Returns:
|
|
62
62
|
PagedResponse of RAWDatabase objects.
|
|
63
63
|
"""
|
|
64
|
-
return self.
|
|
64
|
+
return self._paginate(limit=limit, cursor=cursor)
|
|
65
|
+
|
|
66
|
+
def iterate(
|
|
67
|
+
self,
|
|
68
|
+
limit: int = 100,
|
|
69
|
+
) -> Iterable[list[RAWDatabase]]:
|
|
70
|
+
"""Iterate over all databases in CDF.
|
|
71
|
+
|
|
72
|
+
Args:
|
|
73
|
+
limit: Maximum number of items to return per page.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Iterable of lists of RAWDatabase objects.
|
|
77
|
+
"""
|
|
78
|
+
return self._iterate(limit=limit)
|
|
65
79
|
|
|
66
80
|
def list(self, limit: int | None = None) -> list[RAWDatabase]:
|
|
67
81
|
"""List all databases in CDF.
|
|
@@ -95,7 +109,7 @@ class RawTablesAPI(CDFResourceAPI[RAWTable, RAWTable, RAWTable]):
|
|
|
95
109
|
},
|
|
96
110
|
)
|
|
97
111
|
|
|
98
|
-
def
|
|
112
|
+
def _validate_page_response(self, response: SuccessResponse2 | ItemsSuccessResponse2) -> PagedResponse[RAWTable]:
|
|
99
113
|
"""Parse a page response. Note: db_name must be injected separately."""
|
|
100
114
|
return PagedResponse[RAWTable].model_validate_json(response.body)
|
|
101
115
|
|
|
@@ -137,7 +151,7 @@ class RawTablesAPI(CDFResourceAPI[RAWTable, RAWTable, RAWTable]):
|
|
|
137
151
|
endpoint = f"/raw/dbs/{db_name}/tables/delete"
|
|
138
152
|
self._request_no_response(list(group), "delete", endpoint=endpoint)
|
|
139
153
|
|
|
140
|
-
def
|
|
154
|
+
def paginate(
|
|
141
155
|
self,
|
|
142
156
|
db_name: str,
|
|
143
157
|
limit: int = 100,
|
|
@@ -153,7 +167,23 @@ class RawTablesAPI(CDFResourceAPI[RAWTable, RAWTable, RAWTable]):
|
|
|
153
167
|
Returns:
|
|
154
168
|
PagedResponse of RAWTable objects.
|
|
155
169
|
"""
|
|
156
|
-
return self.
|
|
170
|
+
return self._paginate(cursor=cursor, limit=limit, endpoint_path=f"/raw/dbs/{db_name}/tables")
|
|
171
|
+
|
|
172
|
+
def iterate(
|
|
173
|
+
self,
|
|
174
|
+
db_name: str,
|
|
175
|
+
limit: int = 100,
|
|
176
|
+
) -> Iterable[list[RAWTable]]:
|
|
177
|
+
"""Iterate over all tables in a database in CDF.
|
|
178
|
+
|
|
179
|
+
Args:
|
|
180
|
+
db_name: The name of the database to list tables from.
|
|
181
|
+
limit: Maximum number of items to return per page.
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
Iterable of lists of RAWTable objects.
|
|
185
|
+
"""
|
|
186
|
+
return self._iterate(limit=limit, endpoint_path=f"/raw/dbs/{db_name}/tables")
|
|
157
187
|
|
|
158
188
|
def list(self, db_name: str, limit: int | None = None) -> list[RAWTable]:
|
|
159
189
|
"""List all tables in a database in CDF.
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"""Relationships API for managing CDF relationships.
|
|
2
|
+
|
|
3
|
+
Based on the API specification at:
|
|
4
|
+
https://api-docs.cognite.com/20230101/tag/Relationships/operation/createRelationships
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from collections.abc import Iterable, Sequence
|
|
8
|
+
from typing import Literal
|
|
9
|
+
|
|
10
|
+
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, Endpoint, PagedResponse
|
|
11
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
12
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import ExternalId
|
|
13
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.relationship import RelationshipRequest, RelationshipResponse
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RelationshipsAPI(CDFResourceAPI[ExternalId, RelationshipRequest, RelationshipResponse]):
|
|
17
|
+
"""API for managing CDF relationships."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, http_client: HTTPClient) -> None:
|
|
20
|
+
super().__init__(
|
|
21
|
+
http_client=http_client,
|
|
22
|
+
method_endpoint_map={
|
|
23
|
+
"create": Endpoint(method="POST", path="/relationships", item_limit=1000),
|
|
24
|
+
"retrieve": Endpoint(method="POST", path="/relationships/byids", item_limit=1000),
|
|
25
|
+
"update": Endpoint(method="POST", path="/relationships/update", item_limit=1000),
|
|
26
|
+
"delete": Endpoint(method="POST", path="/relationships/delete", item_limit=1000),
|
|
27
|
+
"list": Endpoint(method="POST", path="/relationships/list", item_limit=1000),
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def _validate_page_response(
|
|
32
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
33
|
+
) -> PagedResponse[RelationshipResponse]:
|
|
34
|
+
return PagedResponse[RelationshipResponse].model_validate_json(response.body)
|
|
35
|
+
|
|
36
|
+
def create(self, items: Sequence[RelationshipRequest]) -> list[RelationshipResponse]:
|
|
37
|
+
"""Create relationships in CDF.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
items: List of RelationshipRequest objects to create.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
List of created RelationshipResponse objects.
|
|
44
|
+
"""
|
|
45
|
+
return self._request_item_response(items, "create")
|
|
46
|
+
|
|
47
|
+
def retrieve(
|
|
48
|
+
self, items: Sequence[ExternalId], ignore_unknown_ids: bool = False, fetch_resources: bool = False
|
|
49
|
+
) -> list[RelationshipResponse]:
|
|
50
|
+
"""Retrieve relationships from CDF.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
items: List of ExternalId objects to retrieve.
|
|
54
|
+
ignore_unknown_ids: Whether to ignore unknown IDs.
|
|
55
|
+
fetch_resources: If true, will try to fetch the resources referred to in the relationship,
|
|
56
|
+
based on the users access rights. Will silently fail to attach the resources
|
|
57
|
+
if the user lacks access to some of them.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
List of retrieved RelationshipResponse objects.
|
|
61
|
+
"""
|
|
62
|
+
return self._request_item_response(
|
|
63
|
+
items,
|
|
64
|
+
method="retrieve",
|
|
65
|
+
extra_body={"ignoreUnknownIds": ignore_unknown_ids, "fetchResources": fetch_resources},
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
def update(
|
|
69
|
+
self, items: Sequence[RelationshipRequest], mode: Literal["patch", "replace"] = "replace"
|
|
70
|
+
) -> list[RelationshipResponse]:
|
|
71
|
+
"""Update relationships in CDF.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
items: List of RelationshipRequest objects to update.
|
|
75
|
+
mode: Update mode, either "patch" or "replace".
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
List of updated RelationshipResponse objects.
|
|
79
|
+
"""
|
|
80
|
+
return self._update(items, mode=mode)
|
|
81
|
+
|
|
82
|
+
def delete(self, items: Sequence[ExternalId], ignore_unknown_ids: bool = False) -> None:
|
|
83
|
+
"""Delete relationships from CDF.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
items: List of ExternalId objects to delete.
|
|
87
|
+
ignore_unknown_ids: Whether to ignore unknown IDs.
|
|
88
|
+
"""
|
|
89
|
+
self._request_no_response(items, "delete", extra_body={"ignoreUnknownIds": ignore_unknown_ids})
|
|
90
|
+
|
|
91
|
+
def paginate(
|
|
92
|
+
self,
|
|
93
|
+
limit: int = 100,
|
|
94
|
+
cursor: str | None = None,
|
|
95
|
+
) -> PagedResponse[RelationshipResponse]:
|
|
96
|
+
"""Get a page of relationships from CDF.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
limit: Maximum number of relationships to return.
|
|
100
|
+
cursor: Cursor for pagination.
|
|
101
|
+
|
|
102
|
+
Returns:
|
|
103
|
+
PagedResponse of RelationshipResponse objects.
|
|
104
|
+
"""
|
|
105
|
+
return self._paginate(
|
|
106
|
+
cursor=cursor,
|
|
107
|
+
limit=limit,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
def iterate(
|
|
111
|
+
self,
|
|
112
|
+
limit: int | None = None,
|
|
113
|
+
) -> Iterable[list[RelationshipResponse]]:
|
|
114
|
+
"""Iterate over all relationships in CDF.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
limit: Maximum total number of relationships to return.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
Iterable of lists of RelationshipResponse objects.
|
|
121
|
+
"""
|
|
122
|
+
return self._iterate(limit=limit)
|
|
123
|
+
|
|
124
|
+
def list(self, limit: int | None = None) -> list[RelationshipResponse]:
|
|
125
|
+
"""List all relationships in CDF.
|
|
126
|
+
|
|
127
|
+
Args:
|
|
128
|
+
limit: Maximum total number of relationships to return.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
List of RelationshipResponse objects.
|
|
132
|
+
"""
|
|
133
|
+
return self._list(limit=limit)
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
from collections.abc import Iterable, Sequence
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse, ResponseItems
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
6
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import InternalId
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.securitycategory import (
|
|
9
|
+
SecurityCategoryRequest,
|
|
10
|
+
SecurityCategoryResponse,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SecurityCategoriesAPI(CDFResourceAPI[InternalId, SecurityCategoryRequest, SecurityCategoryResponse]):
|
|
15
|
+
def __init__(self, http_client: HTTPClient) -> None:
|
|
16
|
+
super().__init__(
|
|
17
|
+
http_client=http_client,
|
|
18
|
+
method_endpoint_map={
|
|
19
|
+
"create": Endpoint(method="POST", path="/securitycategories", item_limit=1000),
|
|
20
|
+
"delete": Endpoint(method="POST", path="/securitycategories/delete", item_limit=1000),
|
|
21
|
+
"list": Endpoint(method="GET", path="/securitycategories", item_limit=1000),
|
|
22
|
+
},
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
def _validate_page_response(
|
|
26
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
27
|
+
) -> PagedResponse[SecurityCategoryResponse]:
|
|
28
|
+
return PagedResponse[SecurityCategoryResponse].model_validate_json(response.body)
|
|
29
|
+
|
|
30
|
+
def _reference_response(self, response: SuccessResponse2) -> ResponseItems[InternalId]:
|
|
31
|
+
return ResponseItems[InternalId].model_validate_json(response.body)
|
|
32
|
+
|
|
33
|
+
def create(self, items: Sequence[SecurityCategoryRequest]) -> list[SecurityCategoryResponse]:
|
|
34
|
+
"""Create security categories in CDF.
|
|
35
|
+
|
|
36
|
+
Args:
|
|
37
|
+
items: List of SecurityCategoryRequest objects to create.
|
|
38
|
+
Returns:
|
|
39
|
+
List of created SecurityCategoryResponse objects.
|
|
40
|
+
"""
|
|
41
|
+
return self._request_item_response(items, "create")
|
|
42
|
+
|
|
43
|
+
def delete(self, items: Sequence[InternalId]) -> None:
|
|
44
|
+
"""Delete security categories from CDF.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
items: List of InternalId objects to delete.
|
|
48
|
+
"""
|
|
49
|
+
self._request_no_response(items, "delete")
|
|
50
|
+
|
|
51
|
+
def paginate(
|
|
52
|
+
self,
|
|
53
|
+
sort: Literal["ASC", "DESC"] = "ASC",
|
|
54
|
+
limit: int = 100,
|
|
55
|
+
cursor: str | None = None,
|
|
56
|
+
) -> PagedResponse[SecurityCategoryResponse]:
|
|
57
|
+
"""Iterate over all security categories in CDF.
|
|
58
|
+
|
|
59
|
+
Args:
|
|
60
|
+
sort: Sort descending or ascending.
|
|
61
|
+
limit: Maximum number of items to return.
|
|
62
|
+
cursor: Cursor for pagination.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
PagedResponse of SecurityCategoryResponse objects.
|
|
66
|
+
"""
|
|
67
|
+
return self._paginate(cursor=cursor, limit=limit, params={"sort": sort})
|
|
68
|
+
|
|
69
|
+
def iterate(
|
|
70
|
+
self,
|
|
71
|
+
sort: Literal["ASC", "DESC"] = "ASC",
|
|
72
|
+
limit: int = 100,
|
|
73
|
+
) -> Iterable[list[SecurityCategoryResponse]]:
|
|
74
|
+
"""Iterate over all security categories in CDF.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
sort: Sort descending or ascending.
|
|
78
|
+
limit: Maximum number of items to return per page.
|
|
79
|
+
|
|
80
|
+
Returns:
|
|
81
|
+
Iterable of lists of SecurityCategoryResponse objects.
|
|
82
|
+
"""
|
|
83
|
+
return self._iterate(limit=limit, params={"sort": sort})
|
|
84
|
+
|
|
85
|
+
def list(
|
|
86
|
+
self,
|
|
87
|
+
limit: int | None = 100,
|
|
88
|
+
) -> list[SecurityCategoryResponse]:
|
|
89
|
+
"""List all security categories in CDF.
|
|
90
|
+
|
|
91
|
+
Returns:
|
|
92
|
+
List of SecurityCategoryResponse objects.
|
|
93
|
+
"""
|
|
94
|
+
return self._list(limit=limit)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
from collections.abc import Iterable, Sequence
|
|
2
|
+
from typing import Literal
|
|
3
|
+
|
|
4
|
+
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse, ResponseItems
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
6
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.request_classes.filters import ClassicFilter
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import InternalOrExternalId
|
|
9
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.sequence import SequenceRequest, SequenceResponse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SequencesAPI(CDFResourceAPI[InternalOrExternalId, SequenceRequest, SequenceResponse]):
|
|
13
|
+
def __init__(self, http_client: HTTPClient) -> None:
|
|
14
|
+
super().__init__(
|
|
15
|
+
http_client=http_client,
|
|
16
|
+
method_endpoint_map={
|
|
17
|
+
"create": Endpoint(method="POST", path="/sequences", item_limit=1000, concurrency_max_workers=1),
|
|
18
|
+
"retrieve": Endpoint(
|
|
19
|
+
method="POST", path="/sequences/byids", item_limit=1000, concurrency_max_workers=1
|
|
20
|
+
),
|
|
21
|
+
"update": Endpoint(method="POST", path="/sequences/update", item_limit=1000, concurrency_max_workers=1),
|
|
22
|
+
"delete": Endpoint(method="POST", path="/sequences/delete", item_limit=1000, concurrency_max_workers=1),
|
|
23
|
+
"list": Endpoint(method="POST", path="/sequences/list", item_limit=1000),
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
def _validate_page_response(
|
|
28
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
29
|
+
) -> PagedResponse[SequenceResponse]:
|
|
30
|
+
return PagedResponse[SequenceResponse].model_validate_json(response.body)
|
|
31
|
+
|
|
32
|
+
def _reference_response(self, response: SuccessResponse2) -> ResponseItems[InternalOrExternalId]:
|
|
33
|
+
return ResponseItems[InternalOrExternalId].model_validate_json(response.body)
|
|
34
|
+
|
|
35
|
+
def create(self, items: Sequence[SequenceRequest]) -> list[SequenceResponse]:
|
|
36
|
+
"""Create sequences in CDF.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
items: List of SequenceRequest objects to create.
|
|
40
|
+
Returns:
|
|
41
|
+
List of created SequenceResponse objects.
|
|
42
|
+
"""
|
|
43
|
+
return self._request_item_response(items, "create")
|
|
44
|
+
|
|
45
|
+
def retrieve(
|
|
46
|
+
self, items: Sequence[InternalOrExternalId], ignore_unknown_ids: bool = False
|
|
47
|
+
) -> list[SequenceResponse]:
|
|
48
|
+
"""Retrieve sequences from CDF.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
items: List of InternalOrExternalId objects to retrieve.
|
|
52
|
+
ignore_unknown_ids: Whether to ignore unknown IDs.
|
|
53
|
+
Returns:
|
|
54
|
+
List of retrieved SequenceResponse objects.
|
|
55
|
+
"""
|
|
56
|
+
return self._request_item_response(
|
|
57
|
+
items, method="retrieve", extra_body={"ignoreUnknownIds": ignore_unknown_ids}
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
def update(
|
|
61
|
+
self, items: Sequence[SequenceRequest], mode: Literal["patch", "replace"] = "replace"
|
|
62
|
+
) -> list[SequenceResponse]:
|
|
63
|
+
"""Update sequences in CDF.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
items: List of SequenceRequest objects to update.
|
|
67
|
+
mode: Update mode, either "patch" or "replace".
|
|
68
|
+
|
|
69
|
+
Returns:
|
|
70
|
+
List of updated SequenceResponse objects.
|
|
71
|
+
"""
|
|
72
|
+
return self._update(items, mode=mode)
|
|
73
|
+
|
|
74
|
+
def delete(self, items: Sequence[InternalOrExternalId], ignore_unknown_ids: bool = False) -> None:
|
|
75
|
+
"""Delete sequences from CDF.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
items: List of InternalOrExternalId objects to delete.
|
|
79
|
+
ignore_unknown_ids: Whether to ignore unknown IDs.
|
|
80
|
+
"""
|
|
81
|
+
self._request_no_response(items, "delete", extra_body={"ignoreUnknownIds": ignore_unknown_ids})
|
|
82
|
+
|
|
83
|
+
def paginate(
|
|
84
|
+
self,
|
|
85
|
+
filter: ClassicFilter | None = None,
|
|
86
|
+
limit: int = 100,
|
|
87
|
+
cursor: str | None = None,
|
|
88
|
+
) -> PagedResponse[SequenceResponse]:
|
|
89
|
+
"""Iterate over all sequences in CDF.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
filter: Filter by data set IDs and/or asset subtree IDs.
|
|
93
|
+
limit: Maximum number of items to return.
|
|
94
|
+
cursor: Cursor for pagination.
|
|
95
|
+
|
|
96
|
+
Returns:
|
|
97
|
+
PagedResponse of SequenceResponse objects.
|
|
98
|
+
"""
|
|
99
|
+
return self._paginate(
|
|
100
|
+
cursor=cursor,
|
|
101
|
+
limit=limit,
|
|
102
|
+
body={"filter": filter.dump() if filter else None},
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
def iterate(
|
|
106
|
+
self,
|
|
107
|
+
filter: ClassicFilter | None = None,
|
|
108
|
+
limit: int = 100,
|
|
109
|
+
) -> Iterable[list[SequenceResponse]]:
|
|
110
|
+
"""Iterate over all sequences in CDF.
|
|
111
|
+
|
|
112
|
+
Args:
|
|
113
|
+
filter: Filter by data set IDs and/or asset subtree IDs.
|
|
114
|
+
limit: Maximum number of items to return per page.
|
|
115
|
+
|
|
116
|
+
Returns:
|
|
117
|
+
Iterable of lists of SequenceResponse objects.
|
|
118
|
+
"""
|
|
119
|
+
return self._iterate(
|
|
120
|
+
limit=limit,
|
|
121
|
+
body={"filter": filter.dump() if filter else None},
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def list(
|
|
125
|
+
self,
|
|
126
|
+
limit: int | None = 100,
|
|
127
|
+
) -> list[SequenceResponse]:
|
|
128
|
+
"""List all sequences in CDF.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
List of SequenceResponse objects.
|
|
132
|
+
"""
|
|
133
|
+
return self._list(limit=limit)
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
from collections.abc import Sequence
|
|
1
|
+
from collections.abc import Iterable, Sequence
|
|
2
2
|
from typing import Any, Literal
|
|
3
3
|
|
|
4
4
|
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse, ResponseItems
|
|
5
5
|
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
6
|
-
from cognite_toolkit._cdf_tk.client.data_classes.identifiers import InternalOrExternalId
|
|
7
|
-
from cognite_toolkit._cdf_tk.client.data_classes.simulator_model import SimulatorModelRequest, SimulatorModelResponse
|
|
8
6
|
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import InternalOrExternalId
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.simulator_model import (
|
|
9
|
+
SimulatorModelRequest,
|
|
10
|
+
SimulatorModelResponse,
|
|
11
|
+
)
|
|
9
12
|
|
|
10
13
|
|
|
11
14
|
class SimulatorModelsAPI(CDFResourceAPI[InternalOrExternalId, SimulatorModelRequest, SimulatorModelResponse]):
|
|
@@ -27,7 +30,7 @@ class SimulatorModelsAPI(CDFResourceAPI[InternalOrExternalId, SimulatorModelRequ
|
|
|
27
30
|
},
|
|
28
31
|
)
|
|
29
32
|
|
|
30
|
-
def
|
|
33
|
+
def _validate_page_response(
|
|
31
34
|
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
32
35
|
) -> PagedResponse[SimulatorModelResponse]:
|
|
33
36
|
return PagedResponse[SimulatorModelResponse].model_validate_json(response.body)
|
|
@@ -87,7 +90,7 @@ class SimulatorModelsAPI(CDFResourceAPI[InternalOrExternalId, SimulatorModelRequ
|
|
|
87
90
|
"""
|
|
88
91
|
self._request_no_response(items, "delete")
|
|
89
92
|
|
|
90
|
-
def
|
|
93
|
+
def paginate(
|
|
91
94
|
self,
|
|
92
95
|
simulator_external_ids: list[str] | None = None,
|
|
93
96
|
limit: int = 100,
|
|
@@ -107,12 +110,35 @@ class SimulatorModelsAPI(CDFResourceAPI[InternalOrExternalId, SimulatorModelRequ
|
|
|
107
110
|
if simulator_external_ids:
|
|
108
111
|
filter_["simulatorExternalIds"] = simulator_external_ids
|
|
109
112
|
|
|
110
|
-
return self.
|
|
113
|
+
return self._paginate(
|
|
111
114
|
cursor=cursor,
|
|
112
115
|
limit=limit,
|
|
113
116
|
body={"filter": filter_ or None},
|
|
114
117
|
)
|
|
115
118
|
|
|
119
|
+
def iterate(
|
|
120
|
+
self,
|
|
121
|
+
simulator_external_ids: list[str] | None = None,
|
|
122
|
+
limit: int = 100,
|
|
123
|
+
) -> Iterable[list[SimulatorModelResponse]]:
|
|
124
|
+
"""Iterate over simulator models in CDF.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
simulator_external_ids: Filter by simulator external IDs.
|
|
128
|
+
limit: Maximum number of items to return per page.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
Iterable of lists of SimulatorModelResponse objects.
|
|
132
|
+
"""
|
|
133
|
+
filter_: dict[str, Any] = {}
|
|
134
|
+
if simulator_external_ids:
|
|
135
|
+
filter_["simulatorExternalIds"] = simulator_external_ids
|
|
136
|
+
|
|
137
|
+
return self._iterate(
|
|
138
|
+
limit=limit,
|
|
139
|
+
body={"filter": filter_ or None},
|
|
140
|
+
)
|
|
141
|
+
|
|
116
142
|
def list(
|
|
117
143
|
self,
|
|
118
144
|
limit: int | None = 100,
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Spaces API for managing CDF data modeling spaces.
|
|
2
|
+
|
|
3
|
+
Based on the API specification at:
|
|
4
|
+
https://api-docs.cognite.com/20230101/tag/Spaces/operation/ApplySpaces
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from collections.abc import Iterable, Sequence
|
|
8
|
+
|
|
9
|
+
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, Endpoint, PagedResponse
|
|
10
|
+
from cognite_toolkit._cdf_tk.client.http_client import HTTPClient, ItemsSuccessResponse2, SuccessResponse2
|
|
11
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.data_modeling import SpaceReference, SpaceRequest, SpaceResponse
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class SpacesAPI(CDFResourceAPI[SpaceReference, SpaceRequest, SpaceResponse]):
|
|
15
|
+
"""API for managing CDF data modeling spaces.
|
|
16
|
+
|
|
17
|
+
Spaces use an apply/upsert pattern for create and update operations.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, http_client: HTTPClient) -> None:
|
|
21
|
+
super().__init__(
|
|
22
|
+
http_client=http_client,
|
|
23
|
+
method_endpoint_map={
|
|
24
|
+
"upsert": Endpoint(method="POST", path="/models/spaces", item_limit=100),
|
|
25
|
+
"retrieve": Endpoint(method="POST", path="/models/spaces/byids", item_limit=100),
|
|
26
|
+
"delete": Endpoint(method="POST", path="/models/spaces/delete", item_limit=100),
|
|
27
|
+
"list": Endpoint(method="GET", path="/models/spaces", item_limit=1000),
|
|
28
|
+
},
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
def _validate_page_response(
|
|
32
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
33
|
+
) -> PagedResponse[SpaceResponse]:
|
|
34
|
+
return PagedResponse[SpaceResponse].model_validate_json(response.body)
|
|
35
|
+
|
|
36
|
+
def apply(self, items: Sequence[SpaceRequest]) -> list[SpaceResponse]:
|
|
37
|
+
"""Apply (create or update) spaces in CDF.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
items: List of SpaceRequest objects to apply.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
List of applied SpaceResponse objects.
|
|
44
|
+
"""
|
|
45
|
+
return self._request_item_response(items, "upsert")
|
|
46
|
+
|
|
47
|
+
def retrieve(self, items: Sequence[SpaceReference]) -> list[SpaceResponse]:
|
|
48
|
+
"""Retrieve spaces from CDF.
|
|
49
|
+
|
|
50
|
+
Args:
|
|
51
|
+
items: List of SpaceReference objects to retrieve.
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
List of retrieved SpaceResponse objects.
|
|
55
|
+
"""
|
|
56
|
+
return self._request_item_response(items, method="retrieve")
|
|
57
|
+
|
|
58
|
+
def delete(self, items: Sequence[SpaceReference]) -> None:
|
|
59
|
+
"""Delete spaces from CDF.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
items: List of SpaceReference objects to delete.
|
|
63
|
+
"""
|
|
64
|
+
self._request_no_response(items, "delete")
|
|
65
|
+
|
|
66
|
+
def paginate(
|
|
67
|
+
self,
|
|
68
|
+
include_global: bool = False,
|
|
69
|
+
limit: int = 100,
|
|
70
|
+
cursor: str | None = None,
|
|
71
|
+
) -> PagedResponse[SpaceResponse]:
|
|
72
|
+
"""Get a page of spaces from CDF.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
include_global: Whether to include global spaces.
|
|
76
|
+
limit: Maximum number of spaces to return.
|
|
77
|
+
cursor: Cursor for pagination.
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
PagedResponse of SpaceResponse objects.
|
|
81
|
+
"""
|
|
82
|
+
return self._paginate(
|
|
83
|
+
cursor=cursor,
|
|
84
|
+
limit=limit,
|
|
85
|
+
params={"includeGlobal": include_global},
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
def iterate(
|
|
89
|
+
self,
|
|
90
|
+
include_global: bool = False,
|
|
91
|
+
limit: int | None = None,
|
|
92
|
+
) -> Iterable[list[SpaceResponse]]:
|
|
93
|
+
"""Iterate over all spaces in CDF.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
include_global: Whether to include global spaces.
|
|
97
|
+
limit: Maximum total number of spaces to return.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
Iterable of lists of SpaceResponse objects.
|
|
101
|
+
"""
|
|
102
|
+
return self._iterate(
|
|
103
|
+
limit=limit,
|
|
104
|
+
params={"includeGlobal": include_global},
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
def list(self, include_global: bool = False, limit: int | None = None) -> list[SpaceResponse]:
|
|
108
|
+
"""List all spaces in CDF.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
include_global: Whether to include global spaces.
|
|
112
|
+
limit: Maximum total number of spaces to return.
|
|
113
|
+
|
|
114
|
+
Returns:
|
|
115
|
+
List of SpaceResponse objects.
|
|
116
|
+
"""
|
|
117
|
+
return self._list(limit=limit, params={"includeGlobal": include_global})
|
|
@@ -4,12 +4,12 @@ from pydantic import TypeAdapter
|
|
|
4
4
|
from rich.console import Console
|
|
5
5
|
|
|
6
6
|
from cognite_toolkit._cdf_tk.client.cdf_client.responses import PagedResponse
|
|
7
|
-
from cognite_toolkit._cdf_tk.client.data_classes.streams import StreamRequest, StreamResponse
|
|
8
7
|
from cognite_toolkit._cdf_tk.client.http_client import (
|
|
9
8
|
HTTPClient,
|
|
10
9
|
ItemsRequest2,
|
|
11
10
|
RequestMessage2,
|
|
12
11
|
)
|
|
12
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.streams import StreamRequest, StreamResponse
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
class StreamsAPI:
|