cognite-toolkit 0.6.97__py3-none-any.whl → 0.7.39__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.py +21 -23
- cognite_toolkit/_cdf_tk/apps/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/apps/_core_app.py +19 -5
- cognite_toolkit/_cdf_tk/apps/_data_app.py +1 -1
- cognite_toolkit/_cdf_tk/apps/_dev_app.py +86 -0
- cognite_toolkit/_cdf_tk/apps/_download_app.py +693 -25
- cognite_toolkit/_cdf_tk/apps/_dump_app.py +44 -102
- cognite_toolkit/_cdf_tk/apps/_import_app.py +41 -0
- cognite_toolkit/_cdf_tk/apps/_landing_app.py +18 -4
- cognite_toolkit/_cdf_tk/apps/_migrate_app.py +424 -9
- cognite_toolkit/_cdf_tk/apps/_modules_app.py +0 -3
- cognite_toolkit/_cdf_tk/apps/_purge.py +15 -43
- cognite_toolkit/_cdf_tk/apps/_run.py +11 -0
- cognite_toolkit/_cdf_tk/apps/_upload_app.py +45 -6
- cognite_toolkit/_cdf_tk/builders/__init__.py +2 -2
- cognite_toolkit/_cdf_tk/builders/_base.py +28 -42
- cognite_toolkit/_cdf_tk/builders/_raw.py +1 -1
- cognite_toolkit/_cdf_tk/cdf_toml.py +20 -1
- cognite_toolkit/_cdf_tk/client/_toolkit_client.py +32 -12
- cognite_toolkit/_cdf_tk/client/api/infield.py +114 -17
- cognite_toolkit/_cdf_tk/client/api/{canvas.py → legacy/canvas.py} +15 -7
- cognite_toolkit/_cdf_tk/client/api/{charts.py → legacy/charts.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_data_modeling.py → legacy/extended_data_modeling.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_files.py → legacy/extended_files.py} +2 -2
- cognite_toolkit/_cdf_tk/client/api/{extended_functions.py → legacy/extended_functions.py} +15 -18
- cognite_toolkit/_cdf_tk/client/api/{extended_raw.py → legacy/extended_raw.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/{extended_timeseries.py → legacy/extended_timeseries.py} +5 -2
- cognite_toolkit/_cdf_tk/client/api/{location_filters.py → legacy/location_filters.py} +1 -1
- cognite_toolkit/_cdf_tk/client/api/legacy/robotics/__init__.py +8 -0
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/capabilities.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/data_postprocessing.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/frames.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/locations.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/maps.py +1 -1
- cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/robots.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/{search_config.py → legacy/search_config.py} +5 -1
- cognite_toolkit/_cdf_tk/client/api/migration.py +177 -4
- cognite_toolkit/_cdf_tk/client/api/project.py +9 -8
- cognite_toolkit/_cdf_tk/client/api/search.py +2 -2
- cognite_toolkit/_cdf_tk/client/api/streams.py +88 -0
- cognite_toolkit/_cdf_tk/client/api/three_d.py +384 -0
- cognite_toolkit/_cdf_tk/client/data_classes/api_classes.py +13 -0
- cognite_toolkit/_cdf_tk/client/data_classes/base.py +37 -33
- cognite_toolkit/_cdf_tk/client/data_classes/charts_data.py +95 -213
- cognite_toolkit/_cdf_tk/client/data_classes/infield.py +32 -18
- cognite_toolkit/_cdf_tk/client/data_classes/instance_api.py +18 -13
- cognite_toolkit/_cdf_tk/client/data_classes/legacy/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/client/data_classes/{canvas.py → legacy/canvas.py} +47 -4
- cognite_toolkit/_cdf_tk/client/data_classes/{charts.py → legacy/charts.py} +3 -3
- cognite_toolkit/_cdf_tk/client/data_classes/{migration.py → legacy/migration.py} +10 -2
- cognite_toolkit/_cdf_tk/client/data_classes/streams.py +90 -0
- cognite_toolkit/_cdf_tk/client/data_classes/three_d.py +112 -0
- cognite_toolkit/_cdf_tk/client/testing.py +42 -18
- cognite_toolkit/_cdf_tk/commands/__init__.py +7 -6
- cognite_toolkit/_cdf_tk/commands/_changes.py +3 -42
- cognite_toolkit/_cdf_tk/commands/_download.py +21 -11
- cognite_toolkit/_cdf_tk/commands/_migrate/__init__.py +0 -2
- cognite_toolkit/_cdf_tk/commands/_migrate/command.py +22 -20
- cognite_toolkit/_cdf_tk/commands/_migrate/conversion.py +140 -92
- cognite_toolkit/_cdf_tk/commands/_migrate/creators.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/data_classes.py +108 -26
- cognite_toolkit/_cdf_tk/commands/_migrate/data_mapper.py +448 -45
- cognite_toolkit/_cdf_tk/commands/_migrate/data_model.py +1 -0
- cognite_toolkit/_cdf_tk/commands/_migrate/default_mappings.py +6 -6
- cognite_toolkit/_cdf_tk/commands/_migrate/issues.py +52 -1
- cognite_toolkit/_cdf_tk/commands/_migrate/migration_io.py +377 -11
- cognite_toolkit/_cdf_tk/commands/_migrate/selectors.py +9 -4
- cognite_toolkit/_cdf_tk/commands/_profile.py +1 -1
- cognite_toolkit/_cdf_tk/commands/_purge.py +36 -39
- cognite_toolkit/_cdf_tk/commands/_questionary_style.py +16 -0
- cognite_toolkit/_cdf_tk/commands/_upload.py +109 -86
- cognite_toolkit/_cdf_tk/commands/about.py +221 -0
- cognite_toolkit/_cdf_tk/commands/auth.py +19 -12
- cognite_toolkit/_cdf_tk/commands/build_cmd.py +16 -62
- cognite_toolkit/_cdf_tk/commands/build_v2/__init__.py +0 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_cmd.py +241 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_input.py +85 -0
- cognite_toolkit/_cdf_tk/commands/build_v2/build_issues.py +27 -0
- cognite_toolkit/_cdf_tk/commands/clean.py +63 -16
- cognite_toolkit/_cdf_tk/commands/deploy.py +20 -17
- cognite_toolkit/_cdf_tk/commands/dump_resource.py +10 -8
- cognite_toolkit/_cdf_tk/commands/init.py +225 -3
- cognite_toolkit/_cdf_tk/commands/modules.py +20 -44
- cognite_toolkit/_cdf_tk/commands/pull.py +6 -19
- cognite_toolkit/_cdf_tk/commands/resources.py +179 -0
- cognite_toolkit/_cdf_tk/commands/run.py +1 -1
- cognite_toolkit/_cdf_tk/constants.py +20 -1
- cognite_toolkit/_cdf_tk/cruds/__init__.py +19 -5
- cognite_toolkit/_cdf_tk/cruds/_base_cruds.py +14 -70
- cognite_toolkit/_cdf_tk/cruds/_data_cruds.py +10 -19
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/__init__.py +4 -1
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/agent.py +11 -9
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/auth.py +5 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/classic.py +45 -44
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/configuration.py +5 -12
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/data_organization.py +4 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/datamodel.py +206 -67
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/extraction_pipeline.py +6 -18
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/fieldops.py +126 -35
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/file.py +7 -28
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/function.py +23 -30
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/hosted_extractors.py +12 -30
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/industrial_tool.py +4 -8
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/location.py +4 -16
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/migration.py +5 -13
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/raw.py +5 -11
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/relationship.py +3 -8
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/robotics.py +16 -45
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/streams.py +94 -0
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/three_d_model.py +3 -7
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/timeseries.py +5 -15
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/transformation.py +75 -32
- cognite_toolkit/_cdf_tk/cruds/_resource_cruds/workflow.py +20 -40
- cognite_toolkit/_cdf_tk/cruds/_worker.py +24 -36
- cognite_toolkit/_cdf_tk/data_classes/_module_toml.py +1 -0
- cognite_toolkit/_cdf_tk/feature_flags.py +16 -36
- cognite_toolkit/_cdf_tk/plugins.py +2 -1
- cognite_toolkit/_cdf_tk/resource_classes/__init__.py +4 -0
- cognite_toolkit/_cdf_tk/resource_classes/capabilities.py +12 -0
- cognite_toolkit/_cdf_tk/resource_classes/functions.py +3 -1
- cognite_toolkit/_cdf_tk/resource_classes/infield_cdm_location_config.py +109 -0
- cognite_toolkit/_cdf_tk/resource_classes/migration.py +8 -17
- cognite_toolkit/_cdf_tk/resource_classes/search_config.py +1 -1
- cognite_toolkit/_cdf_tk/resource_classes/streams.py +29 -0
- cognite_toolkit/_cdf_tk/resource_classes/workflow_version.py +164 -5
- cognite_toolkit/_cdf_tk/storageio/__init__.py +9 -21
- cognite_toolkit/_cdf_tk/storageio/_annotations.py +19 -16
- cognite_toolkit/_cdf_tk/storageio/_applications.py +340 -28
- cognite_toolkit/_cdf_tk/storageio/_asset_centric.py +67 -104
- cognite_toolkit/_cdf_tk/storageio/_base.py +61 -29
- cognite_toolkit/_cdf_tk/storageio/_datapoints.py +276 -20
- cognite_toolkit/_cdf_tk/storageio/_file_content.py +435 -0
- cognite_toolkit/_cdf_tk/storageio/_instances.py +35 -3
- cognite_toolkit/_cdf_tk/storageio/_raw.py +26 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/__init__.py +71 -4
- cognite_toolkit/_cdf_tk/storageio/selectors/_base.py +14 -2
- cognite_toolkit/_cdf_tk/storageio/selectors/_canvas.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_charts.py +14 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_datapoints.py +23 -3
- cognite_toolkit/_cdf_tk/storageio/selectors/_file_content.py +164 -0
- cognite_toolkit/_cdf_tk/storageio/selectors/_three_d.py +34 -0
- cognite_toolkit/_cdf_tk/tk_warnings/other.py +4 -0
- cognite_toolkit/_cdf_tk/tracker.py +2 -2
- cognite_toolkit/_cdf_tk/utils/cdf.py +1 -1
- cognite_toolkit/_cdf_tk/utils/dtype_conversion.py +9 -3
- cognite_toolkit/_cdf_tk/utils/fileio/__init__.py +2 -0
- cognite_toolkit/_cdf_tk/utils/fileio/_base.py +5 -1
- cognite_toolkit/_cdf_tk/utils/fileio/_readers.py +112 -20
- cognite_toolkit/_cdf_tk/utils/fileio/_writers.py +15 -15
- cognite_toolkit/_cdf_tk/utils/http_client/__init__.py +28 -0
- cognite_toolkit/_cdf_tk/utils/http_client/_client.py +285 -18
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes.py +56 -4
- cognite_toolkit/_cdf_tk/utils/http_client/_data_classes2.py +247 -0
- cognite_toolkit/_cdf_tk/utils/http_client/_tracker.py +5 -2
- cognite_toolkit/_cdf_tk/utils/interactive_select.py +60 -18
- cognite_toolkit/_cdf_tk/utils/sql_parser.py +2 -3
- cognite_toolkit/_cdf_tk/utils/useful_types.py +6 -2
- cognite_toolkit/_cdf_tk/validation.py +83 -1
- 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 +5 -4
- cognite_toolkit/_version.py +1 -1
- cognite_toolkit/config.dev.yaml +13 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.39.dist-info}/METADATA +24 -24
- cognite_toolkit-0.7.39.dist-info/RECORD +322 -0
- cognite_toolkit-0.7.39.dist-info/WHEEL +4 -0
- {cognite_toolkit-0.6.97.dist-info → cognite_toolkit-0.7.39.dist-info}/entry_points.txt +1 -0
- cognite_toolkit/_cdf_tk/client/api/robotics/__init__.py +0 -3
- cognite_toolkit/_cdf_tk/commands/_migrate/canvas.py +0 -201
- cognite_toolkit/_cdf_tk/commands/dump_data.py +0 -489
- cognite_toolkit/_cdf_tk/commands/featureflag.py +0 -27
- cognite_toolkit/_cdf_tk/prototypes/import_app.py +0 -41
- cognite_toolkit/_cdf_tk/utils/table_writers.py +0 -434
- cognite_toolkit-0.6.97.dist-info/RECORD +0 -306
- cognite_toolkit-0.6.97.dist-info/WHEEL +0 -4
- cognite_toolkit-0.6.97.dist-info/licenses/LICENSE +0 -18
- /cognite_toolkit/_cdf_tk/{prototypes/commands → client/api/legacy}/__init__.py +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{dml.py → legacy/dml.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{fixed_transformations.py → legacy/fixed_transformations.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/api.py +0 -0
- /cognite_toolkit/_cdf_tk/client/api/{robotics → legacy/robotics}/utlis.py +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{apm_config_v1.py → legacy/apm_config_v1.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extendable_cognite_file.py → legacy/extendable_cognite_file.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_filemetadata.py → legacy/extended_filemetadata.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_filemetdata.py → legacy/extended_filemetdata.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{extended_timeseries.py → legacy/extended_timeseries.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{functions.py → legacy/functions.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{graphql_data_models.py → legacy/graphql_data_models.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{instances.py → legacy/instances.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{location_filters.py → legacy/location_filters.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{pending_instances_ids.py → legacy/pending_instances_ids.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{project.py → legacy/project.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{raw.py → legacy/raw.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{robotics.py → legacy/robotics.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{search_config.py → legacy/search_config.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{sequences.py → legacy/sequences.py} +0 -0
- /cognite_toolkit/_cdf_tk/client/data_classes/{streamlit_.py → legacy/streamlit_.py} +0 -0
- /cognite_toolkit/_cdf_tk/{prototypes/commands/import_.py → commands/_import_cmd.py} +0 -0
|
@@ -6,7 +6,7 @@ from cognite.client._api_client import APIClient
|
|
|
6
6
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
7
7
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
8
8
|
|
|
9
|
-
from cognite_toolkit._cdf_tk.client.data_classes.charts import (
|
|
9
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.charts import (
|
|
10
10
|
Chart,
|
|
11
11
|
ChartList,
|
|
12
12
|
ChartWrite,
|
cognite_toolkit/_cdf_tk/client/api/{extended_data_modeling.py → legacy/extended_data_modeling.py}
RENAMED
|
@@ -16,7 +16,7 @@ from cognite.client.utils._concurrency import execute_tasks
|
|
|
16
16
|
from requests import Response
|
|
17
17
|
|
|
18
18
|
from cognite_toolkit._cdf_tk.client._constants import DATA_MODELING_MAX_DELETE_WORKERS, DATA_MODELING_MAX_WRITE_WORKERS
|
|
19
|
-
from cognite_toolkit._cdf_tk.client.data_classes.instances import InstancesApplyResultList
|
|
19
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.instances import InstancesApplyResultList
|
|
20
20
|
from cognite_toolkit._cdf_tk.client.utils._concurrency import ToolkitConcurrencySettings
|
|
21
21
|
from cognite_toolkit._cdf_tk.client.utils._http_client import ToolkitRetryTracker
|
|
22
22
|
|
|
@@ -9,11 +9,11 @@ from cognite.client.utils._concurrency import execute_tasks
|
|
|
9
9
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
10
10
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
11
11
|
|
|
12
|
-
from cognite_toolkit._cdf_tk.client.data_classes.extended_filemetadata import (
|
|
12
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.extended_filemetadata import (
|
|
13
13
|
ExtendedFileMetadata,
|
|
14
14
|
ExtendedFileMetadataList,
|
|
15
15
|
)
|
|
16
|
-
from cognite_toolkit._cdf_tk.client.data_classes.pending_instances_ids import PendingInstanceId
|
|
16
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.pending_instances_ids import PendingInstanceId
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
class ExtendedFileMetadataAPI(FilesAPI):
|
|
@@ -7,7 +7,7 @@ from rich.console import Console
|
|
|
7
7
|
|
|
8
8
|
from cognite_toolkit._cdf_tk.client.config import ToolkitClientConfig
|
|
9
9
|
from cognite_toolkit._cdf_tk.utils.collection import chunker
|
|
10
|
-
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient,
|
|
10
|
+
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient, RequestMessage2
|
|
11
11
|
from cognite_toolkit._cdf_tk.utils.useful_types import JsonVal
|
|
12
12
|
|
|
13
13
|
|
|
@@ -17,15 +17,16 @@ class ExtendedFunctionsAPI(FunctionsAPI):
|
|
|
17
17
|
config: ToolkitClientConfig,
|
|
18
18
|
api_version: str | None,
|
|
19
19
|
cognite_client: CogniteClient,
|
|
20
|
+
console: Console | None = None,
|
|
20
21
|
) -> None:
|
|
21
22
|
"""
|
|
22
23
|
Extended Functions API to include custom headers and payload preparation.
|
|
23
24
|
"""
|
|
24
25
|
super().__init__(config, api_version, cognite_client)
|
|
25
26
|
self._toolkit_config = config
|
|
26
|
-
self._toolkit_http_client = HTTPClient(config, max_retries=global_config.max_retries)
|
|
27
|
+
self._toolkit_http_client = HTTPClient(config, max_retries=global_config.max_retries, console=console)
|
|
27
28
|
|
|
28
|
-
def create_with_429_retry(self, function: FunctionWrite
|
|
29
|
+
def create_with_429_retry(self, function: FunctionWrite) -> Function:
|
|
29
30
|
"""Create a function with manual retry handling for 429 Too Many Requests responses.
|
|
30
31
|
|
|
31
32
|
This method is a workaround for scenarios where the function creation API is temporarily unavailable
|
|
@@ -33,26 +34,22 @@ class ExtendedFunctionsAPI(FunctionsAPI):
|
|
|
33
34
|
|
|
34
35
|
Args:
|
|
35
36
|
function (FunctionWrite): The function to create.
|
|
36
|
-
console (Console | None): The rich console to use for printing warnings.
|
|
37
37
|
|
|
38
38
|
Returns:
|
|
39
39
|
Function: The created function object.
|
|
40
40
|
"""
|
|
41
|
-
result = self._toolkit_http_client.
|
|
42
|
-
message=
|
|
41
|
+
result = self._toolkit_http_client.request_single_retries(
|
|
42
|
+
message=RequestMessage2(
|
|
43
43
|
endpoint_url=self._toolkit_config.create_api_url("/functions"),
|
|
44
44
|
method="POST",
|
|
45
45
|
body_content={"items": [function.dump(camel_case=True)]},
|
|
46
|
-
)
|
|
47
|
-
console=console,
|
|
46
|
+
)
|
|
48
47
|
)
|
|
49
|
-
result.
|
|
48
|
+
success = result.get_success_or_raise()
|
|
50
49
|
# We assume the API response is one item on a successful creation
|
|
51
|
-
return Function._load(
|
|
50
|
+
return Function._load(success.body_json["items"][0], cognite_client=self._cognite_client)
|
|
52
51
|
|
|
53
|
-
def delete_with_429_retry(
|
|
54
|
-
self, external_id: SequenceNotStr[str], ignore_unknown_ids: bool = False, console: Console | None = None
|
|
55
|
-
) -> None:
|
|
52
|
+
def delete_with_429_retry(self, external_id: SequenceNotStr[str], ignore_unknown_ids: bool = False) -> None:
|
|
56
53
|
"""Delete one or more functions with retry handling for 429 Too Many Requests responses.
|
|
57
54
|
|
|
58
55
|
This method is an improvement over the standard delete method in the FunctionsAPI.
|
|
@@ -72,12 +69,12 @@ class ExtendedFunctionsAPI(FunctionsAPI):
|
|
|
72
69
|
}
|
|
73
70
|
if ignore_unknown_ids:
|
|
74
71
|
body_content["ignoreUnknownIds"] = True
|
|
75
|
-
self._toolkit_http_client.
|
|
76
|
-
message=
|
|
72
|
+
result = self._toolkit_http_client.request_single_retries(
|
|
73
|
+
message=RequestMessage2(
|
|
77
74
|
endpoint_url=self._toolkit_config.create_api_url("/functions/delete"),
|
|
78
75
|
method="POST",
|
|
79
76
|
body_content=body_content,
|
|
80
|
-
)
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
result.get_success_or_raise()
|
|
83
80
|
return None
|
|
@@ -13,8 +13,11 @@ from cognite.client.utils._identifier import IdentifierSequence
|
|
|
13
13
|
from cognite.client.utils._validation import prepare_filter_sort, process_asset_subtree_ids, process_data_set_ids
|
|
14
14
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
15
15
|
|
|
16
|
-
from cognite_toolkit._cdf_tk.client.data_classes.extended_timeseries import
|
|
17
|
-
|
|
16
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.extended_timeseries import (
|
|
17
|
+
ExtendedTimeSeries,
|
|
18
|
+
ExtendedTimeSeriesList,
|
|
19
|
+
)
|
|
20
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.pending_instances_ids import PendingInstanceId
|
|
18
21
|
|
|
19
22
|
|
|
20
23
|
class ExtendedTimeSeriesAPI(TimeSeriesAPI):
|
|
@@ -6,7 +6,7 @@ from cognite.client._api_client import APIClient
|
|
|
6
6
|
from cognite.client.config import ClientConfig
|
|
7
7
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
8
8
|
|
|
9
|
-
from cognite_toolkit._cdf_tk.client.data_classes.location_filters import (
|
|
9
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.location_filters import (
|
|
10
10
|
LocationFilter,
|
|
11
11
|
LocationFilterList,
|
|
12
12
|
LocationFilterWrite,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
from .api import RoboticsAPI
|
|
2
|
+
from .capabilities import CapabilitiesAPI
|
|
3
|
+
from .data_postprocessing import DataPostProcessingAPI
|
|
4
|
+
from .frames import FramesAPI
|
|
5
|
+
from .locations import LocationsAPI
|
|
6
|
+
from .maps import MapsAPI
|
|
7
|
+
|
|
8
|
+
__all__ = ["CapabilitiesAPI", "DataPostProcessingAPI", "FramesAPI", "LocationsAPI", "MapsAPI", "RoboticsAPI"]
|
|
@@ -5,7 +5,7 @@ from cognite.client._api_client import APIClient
|
|
|
5
5
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
6
6
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
7
7
|
|
|
8
|
-
from cognite_toolkit._cdf_tk.client.data_classes.robotics import (
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.robotics import (
|
|
9
9
|
RobotCapability,
|
|
10
10
|
RobotCapabilityList,
|
|
11
11
|
RobotCapabilityWrite,
|
|
@@ -5,7 +5,7 @@ from cognite.client._api_client import APIClient
|
|
|
5
5
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
6
6
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
7
7
|
|
|
8
|
-
from cognite_toolkit._cdf_tk.client.data_classes.robotics import (
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.robotics import (
|
|
9
9
|
DataPostProcessing,
|
|
10
10
|
DataPostProcessingList,
|
|
11
11
|
DataPostProcessingWrite,
|
|
@@ -5,7 +5,7 @@ from cognite.client._api_client import APIClient
|
|
|
5
5
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
6
6
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
7
7
|
|
|
8
|
-
from cognite_toolkit._cdf_tk.client.data_classes.robotics import (
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.robotics import (
|
|
9
9
|
Frame,
|
|
10
10
|
FrameList,
|
|
11
11
|
FrameWrite,
|
|
@@ -5,7 +5,7 @@ from cognite.client._api_client import APIClient
|
|
|
5
5
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
6
6
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
7
7
|
|
|
8
|
-
from cognite_toolkit._cdf_tk.client.data_classes.robotics import (
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.robotics import (
|
|
9
9
|
Location,
|
|
10
10
|
LocationList,
|
|
11
11
|
LocationWrite,
|
|
@@ -5,7 +5,7 @@ from cognite.client._api_client import APIClient
|
|
|
5
5
|
from cognite.client.utils._identifier import IdentifierSequence
|
|
6
6
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
7
7
|
|
|
8
|
-
from cognite_toolkit._cdf_tk.client.data_classes.robotics import (
|
|
8
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.robotics import (
|
|
9
9
|
Map,
|
|
10
10
|
MapList,
|
|
11
11
|
MapWrite,
|
|
@@ -3,8 +3,8 @@ from typing import overload
|
|
|
3
3
|
|
|
4
4
|
from cognite.client._api_client import APIClient
|
|
5
5
|
|
|
6
|
-
from cognite_toolkit._cdf_tk.client.api.robotics.utlis import tmp_disable_gzip
|
|
7
|
-
from cognite_toolkit._cdf_tk.client.data_classes.robotics import Robot, RobotList, RobotWrite, _RobotUpdate
|
|
6
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.robotics.utlis import tmp_disable_gzip
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.robotics import Robot, RobotList, RobotWrite, _RobotUpdate
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
class RobotsAPI(APIClient):
|
|
@@ -4,7 +4,11 @@ from cognite.client import CogniteClient
|
|
|
4
4
|
from cognite.client._api_client import APIClient
|
|
5
5
|
from cognite.client.config import ClientConfig
|
|
6
6
|
|
|
7
|
-
from cognite_toolkit._cdf_tk.client.data_classes.search_config import
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.search_config import (
|
|
8
|
+
SearchConfig,
|
|
9
|
+
SearchConfigList,
|
|
10
|
+
SearchConfigWrite,
|
|
11
|
+
)
|
|
8
12
|
|
|
9
13
|
|
|
10
14
|
class SearchConfigurationsAPI(APIClient):
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import warnings
|
|
2
2
|
from collections.abc import Sequence
|
|
3
3
|
from itertools import groupby
|
|
4
|
-
from typing import TypeVar, overload
|
|
4
|
+
from typing import Literal, TypeVar, cast, overload
|
|
5
5
|
|
|
6
6
|
from cognite.client._constants import DEFAULT_LIMIT_READ
|
|
7
7
|
from cognite.client.data_classes.data_modeling import (
|
|
@@ -10,12 +10,14 @@ from cognite.client.data_classes.data_modeling import (
|
|
|
10
10
|
NodeApplyResultList,
|
|
11
11
|
NodeId,
|
|
12
12
|
NodeList,
|
|
13
|
+
ViewId,
|
|
13
14
|
filters,
|
|
14
15
|
query,
|
|
15
16
|
)
|
|
16
17
|
from cognite.client.utils.useful_types import SequenceNotStr
|
|
17
18
|
|
|
18
|
-
from cognite_toolkit._cdf_tk.client.
|
|
19
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.extended_data_modeling import ExtendedInstancesAPI
|
|
20
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.migration import (
|
|
19
21
|
AssetCentricId,
|
|
20
22
|
CreatedSourceSystem,
|
|
21
23
|
InstanceSource,
|
|
@@ -28,8 +30,6 @@ from cognite_toolkit._cdf_tk.tk_warnings import HighSeverityWarning
|
|
|
28
30
|
from cognite_toolkit._cdf_tk.utils.collection import chunker_sequence
|
|
29
31
|
from cognite_toolkit._cdf_tk.utils.useful_types import AssetCentricType
|
|
30
32
|
|
|
31
|
-
from .extended_data_modeling import ExtendedInstancesAPI
|
|
32
|
-
|
|
33
33
|
|
|
34
34
|
class InstanceSourceAPI:
|
|
35
35
|
def __init__(self, instance_api: ExtendedInstancesAPI) -> None:
|
|
@@ -347,9 +347,182 @@ class SpaceSourceAPI:
|
|
|
347
347
|
return results
|
|
348
348
|
|
|
349
349
|
|
|
350
|
+
_T_Cached = TypeVar("_T_Cached", bound=NodeId | ViewId)
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
class LookupAPI:
|
|
354
|
+
def __init__(self, instance_api: ExtendedInstancesAPI, resource_type: AssetCentricType) -> None:
|
|
355
|
+
self._instance_api = instance_api
|
|
356
|
+
self._resource_type = resource_type
|
|
357
|
+
self._view_id = InstanceSource.get_source()
|
|
358
|
+
self._node_id_by_id: dict[int, NodeId | None] = {}
|
|
359
|
+
self._node_id_by_external_id: dict[str, NodeId | None] = {}
|
|
360
|
+
self._consumer_view_id_by_id: dict[int, ViewId | None] = {}
|
|
361
|
+
self._consumer_view_id_by_external_id: dict[str, ViewId | None] = {}
|
|
362
|
+
self._RETRIEVE_LIMIT = 1000
|
|
363
|
+
|
|
364
|
+
@overload
|
|
365
|
+
def __call__(self, id: int, external_id: None = None) -> NodeId | None: ...
|
|
366
|
+
|
|
367
|
+
@overload
|
|
368
|
+
def __call__(self, id: SequenceNotStr[int], external_id: None = None) -> dict[int, NodeId]: ...
|
|
369
|
+
|
|
370
|
+
@overload
|
|
371
|
+
def __call__(self, *, external_id: str) -> NodeId | None: ...
|
|
372
|
+
|
|
373
|
+
@overload
|
|
374
|
+
def __call__(self, *, external_id: SequenceNotStr[str]) -> dict[str, NodeId]: ...
|
|
375
|
+
|
|
376
|
+
def __call__(
|
|
377
|
+
self, id: int | SequenceNotStr[int] | None = None, external_id: str | SequenceNotStr[str] | None = None
|
|
378
|
+
) -> dict[int, NodeId] | dict[str, NodeId] | NodeId | None:
|
|
379
|
+
"""Lookup NodeId by either internal ID or external ID.
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
id (int | Sequence[int] | None): The internal ID(s) to lookup.
|
|
383
|
+
external_id (str | SequenceNotStr[str] | None): The external ID(s) to lookup.
|
|
384
|
+
|
|
385
|
+
Returns:
|
|
386
|
+
NodeId | dict[int, NodeId] | dict[str, NodeId] | None: The corresponding NodeId(s) if found, otherwise None.
|
|
387
|
+
|
|
388
|
+
"""
|
|
389
|
+
if id is not None and external_id is None:
|
|
390
|
+
return self._lookup(
|
|
391
|
+
identifier=id,
|
|
392
|
+
cache=self._node_id_by_id,
|
|
393
|
+
property_name="id",
|
|
394
|
+
return_type=NodeId,
|
|
395
|
+
input_type=int,
|
|
396
|
+
)
|
|
397
|
+
elif external_id is not None and id is None:
|
|
398
|
+
return self._lookup(
|
|
399
|
+
identifier=external_id,
|
|
400
|
+
cache=self._node_id_by_external_id,
|
|
401
|
+
property_name="classicExternalId",
|
|
402
|
+
return_type=NodeId,
|
|
403
|
+
input_type=str,
|
|
404
|
+
)
|
|
405
|
+
else:
|
|
406
|
+
raise TypeError("Either id or external_id must be provided, but not both.")
|
|
407
|
+
|
|
408
|
+
@overload
|
|
409
|
+
def consumer_view(self, id: int, external_id: None = None) -> ViewId | None: ...
|
|
410
|
+
|
|
411
|
+
@overload
|
|
412
|
+
def consumer_view(self, id: SequenceNotStr[int], external_id: None = None) -> dict[int, ViewId]: ...
|
|
413
|
+
|
|
414
|
+
@overload
|
|
415
|
+
def consumer_view(self, *, external_id: str) -> ViewId | None: ...
|
|
416
|
+
|
|
417
|
+
@overload
|
|
418
|
+
def consumer_view(self, *, external_id: SequenceNotStr[str]) -> dict[str, ViewId]: ...
|
|
419
|
+
|
|
420
|
+
def consumer_view(
|
|
421
|
+
self, id: int | SequenceNotStr[int] | None = None, external_id: str | SequenceNotStr[str] | None = None
|
|
422
|
+
) -> dict[int, ViewId] | dict[str, ViewId] | ViewId | None:
|
|
423
|
+
"""Lookup Consumer ViewId by either internal ID or external ID.
|
|
424
|
+
|
|
425
|
+
Args:
|
|
426
|
+
id (int | Sequence[int] | None): The internal ID(s) to lookup.
|
|
427
|
+
external_id (str | SequenceNotStr[str] | None): The external ID(s) to lookup.
|
|
428
|
+
Returns:
|
|
429
|
+
ViewId | dict[int, ViewId] | dict[str, ViewId] | None
|
|
430
|
+
"""
|
|
431
|
+
if id is not None and external_id is None:
|
|
432
|
+
return self._lookup(
|
|
433
|
+
identifier=id,
|
|
434
|
+
cache=self._consumer_view_id_by_id,
|
|
435
|
+
property_name="id",
|
|
436
|
+
return_type=ViewId,
|
|
437
|
+
input_type=int,
|
|
438
|
+
)
|
|
439
|
+
elif external_id is not None and id is None:
|
|
440
|
+
return self._lookup(
|
|
441
|
+
identifier=external_id,
|
|
442
|
+
cache=self._consumer_view_id_by_external_id,
|
|
443
|
+
property_name="classicExternalId",
|
|
444
|
+
return_type=ViewId,
|
|
445
|
+
input_type=str,
|
|
446
|
+
)
|
|
447
|
+
else:
|
|
448
|
+
raise TypeError("Either id or external_id must be provided, but not both.")
|
|
449
|
+
|
|
450
|
+
def _lookup(
|
|
451
|
+
self,
|
|
452
|
+
identifier: _T | SequenceNotStr[_T],
|
|
453
|
+
cache: dict[_T, _T_Cached | None],
|
|
454
|
+
property_name: Literal["id", "classicExternalId"],
|
|
455
|
+
return_type: type[_T_Cached],
|
|
456
|
+
input_type: type[_T],
|
|
457
|
+
) -> dict[_T, _T_Cached] | _T_Cached | None:
|
|
458
|
+
"""Generic lookup method for both NodeId and ViewId by id or external_id."""
|
|
459
|
+
is_single = isinstance(identifier, input_type)
|
|
460
|
+
# MyPy does not understand that if is_single is True, identifier is _T, else SequenceNotStr[_T].
|
|
461
|
+
identifiers: list[_T] = [identifier] if is_single else list(identifier) # type: ignore[arg-type, list-item]
|
|
462
|
+
|
|
463
|
+
missing = [id_ for id_ in identifiers if id_ not in cache]
|
|
464
|
+
if missing:
|
|
465
|
+
self._fetch_and_cache(missing, by=property_name)
|
|
466
|
+
|
|
467
|
+
if is_single:
|
|
468
|
+
return cache.get(identifier) # type: ignore[arg-type]
|
|
469
|
+
|
|
470
|
+
return {id_: value for id_ in identifiers if isinstance(value := cache.get(id_), return_type)}
|
|
471
|
+
|
|
472
|
+
def _fetch_and_cache(self, identifiers: Sequence[int | str], by: Literal["id", "classicExternalId"]) -> None:
|
|
473
|
+
for chunk in chunker_sequence(identifiers, self._RETRIEVE_LIMIT):
|
|
474
|
+
retrieve_query = query.Query(
|
|
475
|
+
with_={
|
|
476
|
+
"instanceSource": query.NodeResultSetExpression(
|
|
477
|
+
filter=filters.And(
|
|
478
|
+
filters.HasData(views=[self._view_id]),
|
|
479
|
+
filters.Equals(self._view_id.as_property_ref("resourceType"), self._resource_type),
|
|
480
|
+
filters.In(self._view_id.as_property_ref(by), list(chunk)),
|
|
481
|
+
),
|
|
482
|
+
limit=len(chunk),
|
|
483
|
+
),
|
|
484
|
+
},
|
|
485
|
+
select={"instanceSource": query.Select([query.SourceSelector(self._view_id, ["*"])])},
|
|
486
|
+
)
|
|
487
|
+
chunk_response = self._instance_api.query(retrieve_query)
|
|
488
|
+
items = chunk_response.get("instanceSource", [])
|
|
489
|
+
for item in items:
|
|
490
|
+
instance_source = InstanceSource._load(item.dump())
|
|
491
|
+
node_id = instance_source.as_id()
|
|
492
|
+
self._node_id_by_id[instance_source.id_] = node_id
|
|
493
|
+
self._consumer_view_id_by_id[instance_source.id_] = instance_source.consumer_view()
|
|
494
|
+
if instance_source.classic_external_id:
|
|
495
|
+
self._node_id_by_external_id[instance_source.classic_external_id] = node_id
|
|
496
|
+
self._consumer_view_id_by_external_id[instance_source.classic_external_id] = (
|
|
497
|
+
instance_source.consumer_view()
|
|
498
|
+
)
|
|
499
|
+
missing = set(chunk) - set(self._node_id_by_id.keys()) - set(self._node_id_by_external_id.keys())
|
|
500
|
+
if by == "id":
|
|
501
|
+
for missing_id in cast(set[int], missing):
|
|
502
|
+
if missing_id not in self._node_id_by_id:
|
|
503
|
+
self._node_id_by_id[missing_id] = None
|
|
504
|
+
if missing_id not in self._consumer_view_id_by_id:
|
|
505
|
+
self._consumer_view_id_by_id[missing_id] = None
|
|
506
|
+
elif by == "classicExternalId":
|
|
507
|
+
for missing_ext_id in cast(set[str], missing):
|
|
508
|
+
if missing_ext_id not in self._node_id_by_external_id:
|
|
509
|
+
self._node_id_by_external_id[missing_ext_id] = None
|
|
510
|
+
if missing_ext_id not in self._consumer_view_id_by_external_id:
|
|
511
|
+
self._consumer_view_id_by_external_id[missing_ext_id] = None
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
class MigrationLookupAPI:
|
|
515
|
+
def __init__(self, instance_api: ExtendedInstancesAPI) -> None:
|
|
516
|
+
self.assets = LookupAPI(instance_api, "asset")
|
|
517
|
+
self.events = LookupAPI(instance_api, "event")
|
|
518
|
+
self.files = LookupAPI(instance_api, "file")
|
|
519
|
+
self.time_series = LookupAPI(instance_api, "timeseries")
|
|
520
|
+
|
|
521
|
+
|
|
350
522
|
class MigrationAPI:
|
|
351
523
|
def __init__(self, instance_api: ExtendedInstancesAPI) -> None:
|
|
352
524
|
self.instance_source = InstanceSourceAPI(instance_api)
|
|
353
525
|
self.resource_view_mapping = ResourceViewMappingAPI(instance_api)
|
|
354
526
|
self.created_source_system = CreatedSourceSystemAPI(instance_api)
|
|
355
527
|
self.space_source = SpaceSourceAPI(instance_api)
|
|
528
|
+
self.lookup = MigrationLookupAPI(instance_api)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
from cognite.client import CogniteClient
|
|
2
2
|
|
|
3
3
|
from cognite_toolkit._cdf_tk.client.config import ToolkitClientConfig
|
|
4
|
-
from cognite_toolkit._cdf_tk.client.data_classes.project import ProjectStatusList
|
|
5
|
-
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient,
|
|
4
|
+
from cognite_toolkit._cdf_tk.client.data_classes.legacy.project import ProjectStatusList
|
|
5
|
+
from cognite_toolkit._cdf_tk.utils.http_client import HTTPClient, RequestMessage2
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class ProjectAPI:
|
|
@@ -13,11 +13,12 @@ class ProjectAPI:
|
|
|
13
13
|
|
|
14
14
|
def status(self) -> ProjectStatusList:
|
|
15
15
|
"""Retrieve information about the current project."""
|
|
16
|
-
response = self._http_client.
|
|
17
|
-
|
|
18
|
-
endpoint_url=f"{self._config.base_url}/api/v1/projects
|
|
16
|
+
response = self._http_client.request_single_retries(
|
|
17
|
+
RequestMessage2(
|
|
18
|
+
endpoint_url=f"{self._config.base_url}/api/v1/projects",
|
|
19
|
+
method="GET",
|
|
20
|
+
parameters={"withDataModelingStatus": True},
|
|
19
21
|
)
|
|
20
22
|
)
|
|
21
|
-
response.
|
|
22
|
-
|
|
23
|
-
return ProjectStatusList._load(body["items"], cognite_client=self._cognite_client) # type: ignore[arg-type]
|
|
23
|
+
success = response.get_success_or_raise()
|
|
24
|
+
return ProjectStatusList._load(success.body_json["items"], cognite_client=self._cognite_client)
|
|
@@ -2,8 +2,8 @@ from cognite.client import CogniteClient
|
|
|
2
2
|
from cognite.client._api_client import APIClient
|
|
3
3
|
from cognite.client.config import ClientConfig
|
|
4
4
|
|
|
5
|
-
from .location_filters import LocationFiltersAPI
|
|
6
|
-
from .search_config import SearchConfigurationsAPI
|
|
5
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.location_filters import LocationFiltersAPI
|
|
6
|
+
from cognite_toolkit._cdf_tk.client.api.legacy.search_config import SearchConfigurationsAPI
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class SearchAPI(APIClient):
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
from collections.abc import Sequence
|
|
2
|
+
|
|
3
|
+
from pydantic import TypeAdapter
|
|
4
|
+
from rich.console import Console
|
|
5
|
+
|
|
6
|
+
from cognite_toolkit._cdf_tk.client.data_classes.api_classes import PagedResponse
|
|
7
|
+
from cognite_toolkit._cdf_tk.client.data_classes.streams import StreamRequest, StreamResponse
|
|
8
|
+
from cognite_toolkit._cdf_tk.utils.http_client import (
|
|
9
|
+
HTTPClient,
|
|
10
|
+
ItemsRequest2,
|
|
11
|
+
RequestMessage2,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class StreamsAPI:
|
|
16
|
+
ENDPOINT = "/streams"
|
|
17
|
+
|
|
18
|
+
def __init__(self, http_client: HTTPClient, console: Console) -> None:
|
|
19
|
+
self._http_client = http_client
|
|
20
|
+
self._console = console
|
|
21
|
+
self._config = http_client.config
|
|
22
|
+
|
|
23
|
+
def create(self, items: Sequence[StreamRequest]) -> list[StreamResponse]:
|
|
24
|
+
"""Create one or more streams.
|
|
25
|
+
|
|
26
|
+
Args:
|
|
27
|
+
items: Sequence of StreamRequest items to create.
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
List of created StreamResponse items.
|
|
31
|
+
"""
|
|
32
|
+
responses = self._http_client.request_items_retries(
|
|
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
|
+
|
|
42
|
+
def delete(self, external_id: str) -> None:
|
|
43
|
+
"""Delete stream using its external ID.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
external_id: External ID of the stream to delete.
|
|
47
|
+
"""
|
|
48
|
+
response = self._http_client.request_single_retries(
|
|
49
|
+
RequestMessage2(
|
|
50
|
+
endpoint_url=self._config.create_api_url(f"{self.ENDPOINT}/{external_id}"),
|
|
51
|
+
method="DELETE",
|
|
52
|
+
)
|
|
53
|
+
)
|
|
54
|
+
_ = response.get_success_or_raise()
|
|
55
|
+
|
|
56
|
+
def list(self) -> list[StreamResponse]:
|
|
57
|
+
"""List streams.
|
|
58
|
+
|
|
59
|
+
Returns:
|
|
60
|
+
StreamResponseList containing the listed streams.
|
|
61
|
+
"""
|
|
62
|
+
response = self._http_client.request_single_retries(
|
|
63
|
+
RequestMessage2(
|
|
64
|
+
endpoint_url=self._config.create_api_url(self.ENDPOINT),
|
|
65
|
+
method="GET",
|
|
66
|
+
)
|
|
67
|
+
)
|
|
68
|
+
success = response.get_success_or_raise()
|
|
69
|
+
return PagedResponse[StreamResponse].model_validate(success.body_json).items
|
|
70
|
+
|
|
71
|
+
def retrieve(self, external_id: str, include_statistics: bool = True) -> StreamResponse:
|
|
72
|
+
"""Retrieve a stream by its external ID.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
external_id: External ID of the stream to retrieve.
|
|
76
|
+
include_statistics: Whether to include usage statistics in the response.
|
|
77
|
+
Returns:
|
|
78
|
+
StreamResponse item.
|
|
79
|
+
"""
|
|
80
|
+
response = self._http_client.request_single_retries(
|
|
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)
|