List documents
- async AsyncCogniteClient.documents.list(
- filter: Filter | dict[str, Any] | None = None,
- sort: DocumentSort | SortableSourceFileProperty | SortableDocumentProperty | str | list[str] | tuple[SortableSourceFileProperty | SortableDocumentProperty | str | list[str], Literal['asc', 'desc']] | None = None,
- limit: int | None = 25,
-
You can use filters to narrow down the list. Unlike the search method, list does not restrict the number of documents to return, meaning that setting the limit to -1 will return all the documents in your project.
- Parameters:
filter (Filter | dict[str, Any] | None) – Filter | dict[str, Any] | None): The filter to narrow down the documents to return.
sort (DocumentSort | SortableProperty | tuple[SortableProperty, Literal['asc', 'desc']] | None) – The property to sort by. The default order is ascending.
limit (int | None) – Maximum number of documents to return. Defaults to 25. Set to None or -1 to return all documents.
- Returns:
List of documents
- Return type:
Examples
List all PDF documents in your CDF project:
>>> from cognite.client import CogniteClient >>> from cognite.client.data_classes import filters >>> from cognite.client.data_classes.documents import DocumentProperty >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> is_pdf = filters.Equals(DocumentProperty.mime_type, "application/pdf") >>> pdf_documents = client.documents.list(filter=is_pdf)
List documents in your CDF project:
>>> documents = client.documents.list(limit=100)
Iterate over documents, one-by-one:
>>> for document in client.documents(): ... document # do something with the document
Iterate over chunks of documents to reduce memory load:
>>> for document_list in client.documents(chunk_size=250): ... document_list # do something with the document
List all documents in your CDF project sorted by mime/type in descending order:
>>> from cognite.client.data_classes.documents import SortableDocumentProperty >>> documents = client.documents.list(sort=(SortableDocumentProperty.mime_type, "desc"))