Skip to content

Commit f003000

Browse files
committed
feat(document status): support external id and instance id for streaming
1 parent 1c41faa commit f003000

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

cognite/client/_api/documents.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,13 @@ def retrieve_content(
514514
response = self._do_request("POST", f"{self._RESOURCE_PATH}/content", accept="text/plain", json=identifier)
515515
return response.content
516516

517-
def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None:
517+
def retrieve_content_buffer(
518+
self,
519+
buffer: BinaryIO,
520+
id: int | None = None,
521+
external_id: str | None = None,
522+
instance_id: NodeId | None = None,
523+
) -> None:
518524
"""`Retrieve document content into buffer <https://developer.cognite.com/api#tag/Documents/operation/documentsContent>`_
519525
520526
Returns extracted textual information for the given document.
@@ -526,8 +532,10 @@ def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None:
526532
527533
528534
Args:
529-
id (int): The server-generated ID for the document you want to retrieve the content of.
530535
buffer (BinaryIO): The document content is streamed directly into the buffer. This is useful for retrieving large documents.
536+
id (int | None): The server-generated ID for the document you want to retrieve the content of.
537+
external_id (str | None): External ID
538+
instance_id (NodeId | None): Instance ID
531539
532540
Examples:
533541
@@ -539,8 +547,10 @@ def retrieve_content_buffer(self, id: int, buffer: BinaryIO) -> None:
539547
>>> with Path("my_file.txt").open("wb") as buffer:
540548
... client.documents.retrieve_content_buffer(id=123, buffer=buffer)
541549
"""
550+
identifiers = IdentifierSequence.load(ids=id, external_ids=external_id, instance_ids=instance_id).as_singleton()
551+
identifier = identifiers.as_dicts()[0]
542552
with self._do_request(
543-
"POST", f"{self._RESOURCE_PATH}/content", stream=True, accept="text/plain", json={"id": id}
553+
"POST", f"{self._RESOURCE_PATH}/content", stream=True, accept="text/plain", json=identifier
544554
) as response:
545555
for chunk in response.iter_content(chunk_size=2**21):
546556
if chunk: # filter out keep-alive new chunks

0 commit comments

Comments
 (0)