cognite-toolkit 0.7.46__py3-none-any.whl → 0.7.48__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/_migrate_app.py +6 -6
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +6 -4
- 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/containers.py +132 -0
- cognite_toolkit/_cdf_tk/client/api/data_models.py +137 -0
- 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/instances.py +139 -0
- cognite_toolkit/_cdf_tk/client/api/location_filters.py +177 -0
- cognite_toolkit/_cdf_tk/client/api/raw.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/relationships.py +133 -0
- cognite_toolkit/_cdf_tk/client/api/robotics.py +19 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_capabilities.py +127 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_data_postprocessing.py +138 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_frames.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_locations.py +127 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_maps.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/robotics_robots.py +122 -0
- cognite_toolkit/_cdf_tk/client/api/search_config.py +101 -0
- cognite_toolkit/_cdf_tk/client/api/spaces.py +117 -0
- cognite_toolkit/_cdf_tk/client/api/streams.py +63 -55
- cognite_toolkit/_cdf_tk/client/api/three_d.py +293 -277
- cognite_toolkit/_cdf_tk/client/api/views.py +139 -0
- cognite_toolkit/_cdf_tk/client/cdf_client/api.py +42 -7
- cognite_toolkit/_cdf_tk/client/cdf_client/responses.py +11 -0
- cognite_toolkit/_cdf_tk/client/http_client/_client.py +5 -2
- cognite_toolkit/_cdf_tk/client/http_client/_data_classes.py +10 -0
- cognite_toolkit/_cdf_tk/client/http_client/_data_classes2.py +4 -3
- cognite_toolkit/_cdf_tk/client/request_classes/filters.py +75 -0
- cognite_toolkit/_cdf_tk/client/request_classes/graphql.py +28 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/agent.py +8 -2
- cognite_toolkit/_cdf_tk/client/resource_classes/apm_config.py +128 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/cognite_file.py +53 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/data_modeling/_instance.py +22 -11
- cognite_toolkit/_cdf_tk/client/resource_classes/function_schedule.py +8 -4
- cognite_toolkit/_cdf_tk/client/resource_classes/group/group.py +9 -5
- cognite_toolkit/_cdf_tk/client/resource_classes/identifiers.py +7 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/location_filter.py +9 -2
- cognite_toolkit/_cdf_tk/client/resource_classes/relationship.py +9 -3
- cognite_toolkit/_cdf_tk/client/resource_classes/resource_view_mapping.py +38 -0
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_map.py +6 -1
- cognite_toolkit/_cdf_tk/client/resource_classes/robotics/_robot.py +10 -5
- cognite_toolkit/_cdf_tk/client/resource_classes/streams.py +1 -20
- cognite_toolkit/_cdf_tk/client/resource_classes/three_d.py +30 -9
- cognite_toolkit/_cdf_tk/client/testing.py +2 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +5 -5
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +11 -7
- cognite_toolkit/_cdf_tk/commands/build_v2/_module_parser.py +138 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/_modules_parser.py +163 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_cmd.py +83 -96
- cognite_toolkit/_cdf_tk/commands/build_v2/{build_input.py → build_parameters.py} +8 -22
- cognite_toolkit/_cdf_tk/commands/build_v2/data_classes/_modules.py +27 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/data_classes/_resource.py +22 -0
- cognite_toolkit/_cdf_tk/cruds/__init__.py +11 -5
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +14 -30
- cognite_toolkit/_cdf_tk/data_classes/__init__.py +3 -0
- cognite_toolkit/_cdf_tk/data_classes/_issues.py +36 -0
- cognite_toolkit/_cdf_tk/data_classes/_module_directories.py +2 -1
- cognite_toolkit/_cdf_tk/storageio/_base.py +2 -0
- cognite_toolkit/_cdf_tk/storageio/logger.py +163 -0
- cognite_toolkit/_cdf_tk/utils/__init__.py +8 -1
- cognite_toolkit/_cdf_tk/utils/interactive_select.py +3 -1
- cognite_toolkit/_cdf_tk/utils/modules.py +7 -0
- 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.46.dist-info → cognite_toolkit-0.7.48.dist-info}/METADATA +1 -1
- {cognite_toolkit-0.7.46.dist-info → cognite_toolkit-0.7.48.dist-info}/RECORD +76 -46
- cognite_toolkit/_cdf_tk/commands/build_v2/build_issues.py +0 -27
- /cognite_toolkit/_cdf_tk/client/resource_classes/{search_config_resource.py → search_config.py} +0 -0
- {cognite_toolkit-0.7.46.dist-info → cognite_toolkit-0.7.48.dist-info}/WHEEL +0 -0
- {cognite_toolkit-0.7.46.dist-info → cognite_toolkit-0.7.48.dist-info}/entry_points.txt +0 -0
|
@@ -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})
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
from collections.abc import Sequence
|
|
2
2
|
|
|
3
|
-
from
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
from cognite_toolkit._cdf_tk.client.cdf_client.responses import PagedResponse
|
|
3
|
+
from cognite_toolkit._cdf_tk.client.cdf_client import CDFResourceAPI, PagedResponse
|
|
4
|
+
from cognite_toolkit._cdf_tk.client.cdf_client.api import Endpoint
|
|
7
5
|
from cognite_toolkit._cdf_tk.client.http_client import (
|
|
8
6
|
HTTPClient,
|
|
9
|
-
|
|
7
|
+
ItemsSuccessResponse2,
|
|
10
8
|
RequestMessage2,
|
|
9
|
+
SuccessResponse2,
|
|
11
10
|
)
|
|
11
|
+
from cognite_toolkit._cdf_tk.client.resource_classes.identifiers import ExternalId
|
|
12
12
|
from cognite_toolkit._cdf_tk.client.resource_classes.streams import StreamRequest, StreamResponse
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
class StreamsAPI:
|
|
16
|
-
|
|
15
|
+
class StreamsAPI(CDFResourceAPI[ExternalId, StreamRequest, StreamResponse]):
|
|
16
|
+
def __init__(self, http_client: HTTPClient) -> None:
|
|
17
|
+
super().__init__(
|
|
18
|
+
http_client=http_client,
|
|
19
|
+
method_endpoint_map={
|
|
20
|
+
"create": Endpoint(method="POST", path="/streams", item_limit=1),
|
|
21
|
+
"delete": Endpoint(method="POST", path="/streams/delete", item_limit=1),
|
|
22
|
+
"retrieve": Endpoint(method="GET", path="/streams/{streamId}", item_limit=1),
|
|
23
|
+
"list": Endpoint(method="GET", path="/streams", item_limit=1000),
|
|
24
|
+
},
|
|
25
|
+
)
|
|
17
26
|
|
|
18
|
-
def
|
|
19
|
-
self
|
|
20
|
-
|
|
21
|
-
|
|
27
|
+
def _validate_page_response(
|
|
28
|
+
self, response: SuccessResponse2 | ItemsSuccessResponse2
|
|
29
|
+
) -> PagedResponse[StreamResponse]:
|
|
30
|
+
return PagedResponse[StreamResponse].model_validate_json(response.body)
|
|
22
31
|
|
|
23
32
|
def create(self, items: Sequence[StreamRequest]) -> list[StreamResponse]:
|
|
24
33
|
"""Create one or more streams.
|
|
@@ -29,60 +38,59 @@ class StreamsAPI:
|
|
|
29
38
|
Returns:
|
|
30
39
|
List of created StreamResponse items.
|
|
31
40
|
"""
|
|
32
|
-
|
|
33
|
-
ItemsRequest2(
|
|
34
|
-
endpoint_url=self._config.create_api_url(self.ENDPOINT),
|
|
35
|
-
method="POST",
|
|
36
|
-
items=items,
|
|
37
|
-
)
|
|
38
|
-
)
|
|
39
|
-
responses.raise_for_status()
|
|
40
|
-
return TypeAdapter(list[StreamResponse]).validate_python(responses.get_items())
|
|
41
|
+
return self._request_item_response(items, "create")
|
|
41
42
|
|
|
42
|
-
def delete(self,
|
|
43
|
-
"""Delete
|
|
43
|
+
def delete(self, items: Sequence[ExternalId], ignore_unknown_ids: bool = False) -> None:
|
|
44
|
+
"""Delete streams using their external IDs.
|
|
44
45
|
|
|
45
46
|
Args:
|
|
46
|
-
|
|
47
|
+
items: Sequence of ExternalId objects to delete.
|
|
48
|
+
ignore_unknown_ids: Whether to ignore unknown IDs.
|
|
47
49
|
"""
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
_ = response.get_success_or_raise()
|
|
50
|
+
if ignore_unknown_ids:
|
|
51
|
+
# The endpoint does not support ignoreUnknownIds, so we have to do it on the client side
|
|
52
|
+
return self._request_item_split_retries_no_response(items, "delete")
|
|
53
|
+
else:
|
|
54
|
+
return self._request_no_response(items, "delete")
|
|
55
55
|
|
|
56
|
-
def
|
|
57
|
-
|
|
56
|
+
def retrieve(
|
|
57
|
+
self, items: Sequence[ExternalId], include_statistics: bool = False, ignore_unknown_ids: bool = False
|
|
58
|
+
) -> list[StreamResponse]:
|
|
59
|
+
"""Retrieve streams by their external IDs.
|
|
60
|
+
|
|
61
|
+
Note: The streams API only supports retrieving one stream at a time via path parameter.
|
|
62
|
+
|
|
63
|
+
Args:
|
|
64
|
+
items: Sequence of ExternalId objects to retrieve.
|
|
65
|
+
include_statistics: Whether to include usage statistics in the response.
|
|
66
|
+
ignore_unknown_ids: Whether to ignore unknown IDs.
|
|
58
67
|
|
|
59
68
|
Returns:
|
|
60
|
-
|
|
69
|
+
List of StreamResponse items.
|
|
61
70
|
"""
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
71
|
+
results: list[StreamResponse] = []
|
|
72
|
+
endpoint = self._method_endpoint_map["retrieve"]
|
|
73
|
+
for item in items:
|
|
74
|
+
response = self._http_client.request_single_retries(
|
|
75
|
+
RequestMessage2(
|
|
76
|
+
endpoint_url=self._make_url(endpoint.path.format(streamId=item.external_id)),
|
|
77
|
+
method=endpoint.method,
|
|
78
|
+
parameters={"includeStatistics": include_statistics},
|
|
79
|
+
)
|
|
66
80
|
)
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
81
|
+
if isinstance(response, SuccessResponse2):
|
|
82
|
+
results.append(StreamResponse.model_validate(response.body_json))
|
|
83
|
+
elif ignore_unknown_ids:
|
|
84
|
+
continue
|
|
85
|
+
_ = response.get_success_or_raise()
|
|
86
|
+
return results
|
|
70
87
|
|
|
71
|
-
def
|
|
72
|
-
"""
|
|
88
|
+
def list(self) -> list[StreamResponse]:
|
|
89
|
+
"""List all streams.
|
|
90
|
+
|
|
91
|
+
Note: The streams API does not support pagination.
|
|
73
92
|
|
|
74
|
-
Args:
|
|
75
|
-
external_id: External ID of the stream to retrieve.
|
|
76
|
-
include_statistics: Whether to include usage statistics in the response.
|
|
77
93
|
Returns:
|
|
78
|
-
StreamResponse
|
|
94
|
+
List of StreamResponse items.
|
|
79
95
|
"""
|
|
80
|
-
|
|
81
|
-
RequestMessage2(
|
|
82
|
-
endpoint_url=self._config.create_api_url(f"{self.ENDPOINT}/{external_id}"),
|
|
83
|
-
method="GET",
|
|
84
|
-
parameters={"includeStatistics": include_statistics},
|
|
85
|
-
)
|
|
86
|
-
)
|
|
87
|
-
success = response.get_success_or_raise()
|
|
88
|
-
return StreamResponse.model_validate(success.body_json)
|
|
96
|
+
return self._list(limit=None)
|