cmem_client.repositories.files¤
Repository for the file resources of DataIntegration projects.
Provides FilesRepository for uploading, reading, exporting and deleting the files of a
project. Items are keyed by the composite key project_id:file_path, so a single
repository spans the files of all projects.
Examples:
Upload a local file into a project and read it back:
>>> from pathlib import Path
>>> from cmem_client.client import Client
>>> client = Client.from_env()
>>> client.files.import_item(
... path=Path("customers.csv"), key="my-project:customers.csv"
... )
>>> client.files.read("my-project:customers.csv")
List the files of a single project and inspect one of them:
>>> for resource in client.files.get_resources("my-project"):
... print(resource.name)
>>> client.files.delete_item("my-project:customers.csv")
Classes:
- FilesDeleteConfig – Files Delete Configuration.
- FilesExportConfig – Files Export Configuration.
- FilesImportConfig – Files Import Configuration.
- FilesRepository – Repository for files
FilesDeleteConfig¤
Bases: DeleteConfig
Files Delete Configuration.
Attributes:
- model_config –
FilesExportConfig¤
Bases: ExportConfig
Files Export Configuration.
Attributes:
- model_config –
FilesImportConfig¤
Bases: ImportConfig
Files Import Configuration.
Attributes:
- use_archive_handler (
bool) – Defaults to False here, unlike the base class, so a path is imported as a single file instead of being unpacked by the ArchiveHandler. - remote_file_url (
str | None) – URL to stream the file content from instead of reading it from a local path. If set, the path argument may be omitted.
model_config¤
remote_file_url¤
use_archive_handler¤
FilesRepository¤
Bases: PlainListRepository, ImportItemProtocol, DeleteItemProtocol, ExportItemProtocol
Repository for files
Functions:
- delete_all – Delete all items from the repository
- delete_item – Delete an item from the repository
- export_item – Export an item from the repository to a file path.
- fetch_data – Fetch all file resources from all projects.
- get_resource_metadata – Retrieve metadata of a single resource
- get_resource_usage – Retrieve usage of a single resource
- get_resources – Fetch the list of file resources for a specific project.
- import_item – Import an exported file to the repository
- items – Get the items of the repository
- keys – Get the keys of the repository
- read – Read the content of a file into memory.
- values – Get the values of the repository
Attributes:
- logger (
Logger) – Gets the client logger
delete_all¤
Delete all items from the repository
delete_item¤
Delete an item from the repository
Parameters:
- key (
str) – The key of the item to delete - skip_if_missing (
bool) – If True, it is ignored if the deleted item even exists - configuration (
DeleteItemConfig) – Optional configuration for deletion
Raises:
RepositoryModificationError– if an error occurs while creating the itemHTTPError– for any other http error
export_item¤
Export an item from the repository to a file path.
Parameters:
- key (
str) – The key identifying the item to export. - path (
Path | None) – The target file path for export. If None, a path will be generated. - replace (
bool) – Whether to replace existing files at the target path. - configuration (
ExportItemConfig_contra | None) – Optional configuration for export behavior.
Returns:
Path– The actual path where the item was exported.
Raises:
RepositoryItemNotFoundError– If the specified item key is not found.RepositoryReadError– If there’s an error during export or path mismatch.
fetch_data¤
Fetch all file resources from all projects.
get_resource_metadata¤
Retrieve metadata of a single resource
get_resource_usage¤
Retrieve usage of a single resource
get_resources¤
Fetch the list of file resources for a specific project.
import_item¤
Import an exported file to the repository
By default, automatically handles zip files, directories, and single files using ImportItem model. Can be disabled by setting use_archive_handler=False in the configuration.
Returns:
str– The key of the imported item.
Raises:
RepositoryModificationError– If the item already exists and the conflict policy is FAIL, if the import type is not allowed for this repository, if the import request failed, or if the item is not present afterwards.
items¤
Get the items of the repository
keys¤
Get the keys of the repository
logger¤
Gets the client logger
read¤
Read the content of a file into memory.
Parameters:
- key (
str) – Composite key in format ‘project_id:file_path’
Returns:
bytes– The raw content of the file.
Raises:
FilesReadError– If the key is malformed or the request fails.FilesNotFoundError– If the file does not exist in the project.
values¤
Get the values of the repository