From 2c55744c244e97cc76d1e6d89b5677d75025cd69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= Date: Sun, 24 Nov 2024 10:30:06 +0100 Subject: [PATCH 1/7] feat(documents content): use new POST variant The GET variant was deprecated in favor of having a request body to handle different arguments. --- cognite/client/_api/documents.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cognite/client/_api/documents.py b/cognite/client/_api/documents.py index 8a8d4a58b6..fda275e222 100644 --- a/cognite/client/_api/documents.py +++ b/cognite/client/_api/documents.py @@ -500,7 +500,7 @@ def retrieve_content(self, id: int) -> bytes: >>> client = CogniteClient() >>> content = client.documents.retrieve_content(id=123) """ - response = self._do_request("GET", f"{self._RESOURCE_PATH}/{id}/content", accept="text/plain") + response = self._do_request("POST", f"{self._RESOURCE_PATH}/content", accept="text/plain", json={"id": id}) return response.content def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None: @@ -529,7 +529,7 @@ def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None: ... client.documents.retrieve_content_buffer(id=123, buffer=buffer) """ with self._do_request( - "GET", f"{self._RESOURCE_PATH}/{id}/content", stream=True, accept="text/plain" + "POST", f"{self._RESOURCE_PATH}/content", stream=True, accept="text/plain", json={"id": id} ) as response: for chunk in response.iter_content(chunk_size=2**21): if chunk: # filter out keep-alive new chunks From 1c41faaa8e7cfb24d9a54cbe28bd7c9b2d87b962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= Date: Sun, 24 Nov 2024 10:41:50 +0100 Subject: [PATCH 2/7] feat(document content): support external id and instance id --- cognite/client/_api/documents.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cognite/client/_api/documents.py b/cognite/client/_api/documents.py index fda275e222..efc69915de 100644 --- a/cognite/client/_api/documents.py +++ b/cognite/client/_api/documents.py @@ -8,6 +8,7 @@ from cognite.client._constants import DEFAULT_LIMIT_READ from cognite.client.data_classes import filters from cognite.client.data_classes.aggregations import AggregationFilter, UniqueResultList +from cognite.client.data_classes.data_modeling.ids import NodeId from cognite.client.data_classes.documents import ( Document, DocumentHighlightList, @@ -19,6 +20,7 @@ TemporaryLink, ) from cognite.client.data_classes.filters import _BASIC_FILTERS, Filter, _validate_filter +from cognite.client.utils._identifier import IdentifierSequence if TYPE_CHECKING: from cognite.client import ClientConfig, CogniteClient @@ -475,7 +477,12 @@ def aggregate_unique_properties( limit=limit, ) - def retrieve_content(self, id: int) -> bytes: + def retrieve_content( + self, + id: int | None = None, + external_id: str | None = None, + instance_id: NodeId | None = None, + ) -> bytes: """`Retrieve document content `_ Returns extracted textual information for the given document. @@ -487,7 +494,9 @@ def retrieve_content(self, id: int) -> bytes: Args: - id (int): The server-generated ID for the document you want to retrieve the content of. + id (int | None): The server-generated ID for the document you want to retrieve the content of. + external_id (str | None): External ID + instance_id (NodeId | None): Instance ID Returns: bytes: The content of the document. @@ -500,7 +509,9 @@ def retrieve_content(self, id: int) -> bytes: >>> client = CogniteClient() >>> content = client.documents.retrieve_content(id=123) """ - response = self._do_request("POST", f"{self._RESOURCE_PATH}/content", accept="text/plain", json={"id": id}) + identifiers = IdentifierSequence.load(ids=id, external_ids=external_id, instance_ids=instance_id).as_singleton() + identifier = identifiers.as_dicts()[0] + response = self._do_request("POST", f"{self._RESOURCE_PATH}/content", accept="text/plain", json=identifier) return response.content def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None: From f003000195ad9dfe8d1341bf7544d040043061ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= Date: Sun, 24 Nov 2024 10:46:37 +0100 Subject: [PATCH 3/7] feat(document status): support external id and instance id for streaming --- cognite/client/_api/documents.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cognite/client/_api/documents.py b/cognite/client/_api/documents.py index efc69915de..9d3f0812e7 100644 --- a/cognite/client/_api/documents.py +++ b/cognite/client/_api/documents.py @@ -514,7 +514,13 @@ def retrieve_content( response = self._do_request("POST", f"{self._RESOURCE_PATH}/content", accept="text/plain", json=identifier) return response.content - def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None: + def retrieve_content_buffer( + self, + buffer: BinaryIO, + id: int | None = None, + external_id: str | None = None, + instance_id: NodeId | None = None, + ) -> None: """`Retrieve document content into buffer `_ Returns extracted textual information for the given document. @@ -526,8 +532,10 @@ def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None: Args: - id (int): The server-generated ID for the document you want to retrieve the content of. buffer (BinaryIO): The document content is streamed directly into the buffer. This is useful for retrieving large documents. + id (int | None): The server-generated ID for the document you want to retrieve the content of. + external_id (str | None): External ID + instance_id (NodeId | None): Instance ID Examples: @@ -539,8 +547,10 @@ def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None: >>> with Path("my_file.txt").open("wb") as buffer: ... client.documents.retrieve_content_buffer(id=123, buffer=buffer) """ + identifiers = IdentifierSequence.load(ids=id, external_ids=external_id, instance_ids=instance_id).as_singleton() + identifier = identifiers.as_dicts()[0] with self._do_request( - "POST", f"{self._RESOURCE_PATH}/content", stream=True, accept="text/plain", json={"id": id} + "POST", f"{self._RESOURCE_PATH}/content", stream=True, accept="text/plain", json=identifier ) as response: for chunk in response.iter_content(chunk_size=2**21): if chunk: # filter out keep-alive new chunks From b21c8c64fc4002ea929a6ae627bcb2663dff5cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= Date: Sun, 24 Nov 2024 10:48:53 +0100 Subject: [PATCH 4/7] bump version --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3382eba294..753e9b2128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.70.0] - 2024-11-24 +### Added +- Documents content endpoint now support external id and instance id. + ## [7.69.0] - 2024-11-23 ### Added - Synthetic Datapoints API has better support for `instance_id`. Previously you had to specify these directly diff --git a/pyproject.toml b/pyproject.toml index fd57af7ab1..9aacfb3ce5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.69.0" +version = "7.70.0" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" From f231915935a9efae62f4cd091cce3640f775e426 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= Date: Sun, 24 Nov 2024 10:54:03 +0100 Subject: [PATCH 5/7] Revert "bump version" This reverts commit b21c8c64fc4002ea929a6ae627bcb2663dff5cad. --- CHANGELOG.md | 4 ---- pyproject.toml | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 753e9b2128..3382eba294 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,10 +17,6 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. -## [7.70.0] - 2024-11-24 -### Added -- Documents content endpoint now support external id and instance id. - ## [7.69.0] - 2024-11-23 ### Added - Synthetic Datapoints API has better support for `instance_id`. Previously you had to specify these directly diff --git a/pyproject.toml b/pyproject.toml index 9aacfb3ce5..fd57af7ab1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.70.0" +version = "7.69.0" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" From 25380d186f21a67b7f1238e0b24605e11525d1fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= Date: Sun, 24 Nov 2024 15:04:03 +0100 Subject: [PATCH 6/7] Reapply "bump version" This reverts commit f231915935a9efae62f4cd091cce3640f775e426. --- CHANGELOG.md | 4 ++++ pyproject.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3382eba294..753e9b2128 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ Changes are grouped as follows - `Fixed` for any bug fixes. - `Security` in case of vulnerabilities. +## [7.70.0] - 2024-11-24 +### Added +- Documents content endpoint now support external id and instance id. + ## [7.69.0] - 2024-11-23 ### Added - Synthetic Datapoints API has better support for `instance_id`. Previously you had to specify these directly diff --git a/pyproject.toml b/pyproject.toml index fd57af7ab1..9aacfb3ce5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] name = "cognite-sdk" -version = "7.69.0" +version = "7.70.0" description = "Cognite Python SDK" readme = "README.md" documentation = "https://cognite-sdk-python.readthedocs-hosted.com" From bb38f03fb425b1c8896a66e610615353b6d9a789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=98en=20Fylling?= <7851860+andersfylling@users.noreply.github.com> Date: Sun, 24 Nov 2024 15:12:08 +0100 Subject: [PATCH 7/7] Update _version.py --- cognite/client/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cognite/client/_version.py b/cognite/client/_version.py index 605c9152ed..c05b794005 100644 --- a/cognite/client/_version.py +++ b/cognite/client/_version.py @@ -1,4 +1,4 @@ from __future__ import annotations -__version__ = "7.69.0" +__version__ = "7.70.0" __api_subversion__ = "20230101"