Download
- async AsyncCogniteClient.files.download(
- directory: str | Path,
- id: int | Sequence[int] | None = None,
- external_id: str | SequenceNotStr[str] | None = None,
- instance_id: NodeId | Sequence[NodeId] | None = None,
- keep_directory_structure: bool = False,
- resolve_duplicate_file_names: bool = False,
Download files by id or external id.
This method will stream all files to disk, never keeping more than 2MB in memory per worker. The files will be stored in the provided directory using the file name retrieved from the file metadata in CDF. You can also choose to keep the directory structure from CDF so that the files will be stored in subdirectories matching the directory attribute on the files. When missing, the (root) directory is used. By default, duplicate file names to the same local folder will be resolved by only keeping one of the files. You can choose to resolve this by appending a number to the file name using the resolve_duplicate_file_names argument.
Warning
If you are downloading several files at once, be aware that file name collisions lead to all-but-one of the files missing. A warning is issued when this happens, listing the affected files.
- Parameters:
directory (str | Path) – Directory to download the file(s) to.
id (int | Sequence[int] | None) – Id or list of ids
external_id (str | SequenceNotStr[str] | None) – External ID or list of external ids.
instance_id (NodeId | Sequence[NodeId] | None) – Instance ID or list of instance ids.
keep_directory_structure (bool) – Whether or not to keep the directory hierarchy in CDF, creating subdirectories as needed below the given directory.
resolve_duplicate_file_names (bool) – Whether or not to resolve duplicate file names by appending a number on duplicate file names
Examples
Download files by id and external id into directory ‘my_directory’:
>>> from cognite.client import CogniteClient, AsyncCogniteClient >>> client = CogniteClient() >>> # async_client = AsyncCogniteClient() # another option >>> client.files.download( ... directory="my_directory", id=[1, 2, 3], external_id=["abc", "def"] ... )
Download files by id to the current directory:
>>> client.files.download(directory=".", id=[1, 2, 3])