File transfer¶
See Work with sandbox files for upload and download scenarios, and Customize the SDK
for transfer implementations. Import file types from contree_sdk.files.
Public file-transfer contracts and client-backed implementations.
- class contree_sdk.files.AsyncClientFileTransfer(client, *, max_concurrency=4, on_progress=None)[source]¶
File transfer using a caller-owned asynchronous contree-client.
- max_concurrency = 4¶
-
on_progress:
Callable[[TransferProgress],None] |None= None¶
- async iter_file(image_uuid, path)[source]¶
Yield file content. Override this buffered fallback for streaming backends.
- Yields:
File content chunks. Close the generator if iteration stops early.
- Return type:
AsyncGenerator[bytes,None]
- async download_file(image_uuid, path, destination)¶
Atomically save streamed content.
- Return type:
int- Returns:
The number of downloaded bytes.
- async prepare_files(files)¶
- Return type:
dict[str,FileSpec] |None
- async read_stdin(source)¶
- Return type:
str|bytes
- class contree_sdk.files.AsyncFileTransfer[source]¶
Native async counterpart of SyncFileTransfer.
prepare_files limits uploads to max_concurrency workers. It cancels and joins sibling uploads when one fails. Custom backends can replace batching.
- max_concurrency = 4¶
-
on_progress:
Callable[[TransferProgress],None] |None= None¶
- async iter_file(image_uuid, path)[source]¶
Yield file content. Override this buffered fallback for streaming backends.
- Yields:
File content chunks. Close the generator if iteration stops early.
- Return type:
AsyncGenerator[bytes,None]
- class contree_sdk.files.ClientFileTransfer(client, *, max_concurrency=1, on_progress=None)[source]¶
File transfer using a caller-owned synchronous contree-client.
- max_concurrency = 1¶
-
on_progress:
Callable[[TransferProgress],None] |None= None¶
- iter_file(image_uuid, path)[source]¶
Yield file content. Override this buffered fallback for streaming backends.
- Yields:
File content chunks. Close the generator if iteration stops early.
- Return type:
Generator[bytes,None,None]
- download_file(image_uuid, path, destination)¶
Atomically save streamed content.
- Return type:
int- Returns:
The number of downloaded bytes.
- prepare_files(files)¶
- Return type:
dict[str,FileSpec] |None
- read_stdin(source)¶
- Return type:
str|bytes
- class contree_sdk.files.StagedFile(path, uuid, uid=0, gid=0, mode=420)[source]¶
An uploaded file and its destination metadata, detached from a local source.
-
path:
str¶
-
uuid:
str¶
-
uid:
int|None= 0¶
-
gid:
int|None= 0¶
-
mode:
int|None= 420¶
-
path:
- class contree_sdk.files.SyncFileTransfer[source]¶
Replace upload, download, or stdin handling without replacing a session.
Returned FileSpec values identify uploads on the same server as the session. Input streams belong to the caller and must not be closed by this component.
- max_concurrency = 1¶
-
on_progress:
Callable[[TransferProgress],None] |None= None¶
- iter_file(image_uuid, path)[source]¶
Yield file content. Override this buffered fallback for streaming backends.
- Yields:
File content chunks. Close the generator if iteration stops early.
- Return type:
Generator[bytes,None,None]
- class contree_sdk.files.TransferProgress(direction, path, bytes_transferred, total_bytes=None)[source]¶
Completed upload size or cumulative downloaded bytes for one remote path.
-
total_bytes:
int|None= None¶
-
direction:
Literal['upload','download']¶
-
path:
str¶
-
bytes_transferred:
int¶
-
total_bytes:
- class contree_sdk.files.UploadFileSpec(*, uid=0, gid=0, mode=420, path=None, source)[source]¶
-
gid:
int= 0¶
-
mode:
int= 420¶
-
path:
PurePosixPath|str|None= None¶
- classmethod prepare_files(files, default_image_path='/')[source]¶
- Return type:
list[UploadFileSpec]
-
uid:
int= 0¶
-
source:
str|Path|bytes|UploadedFile¶
-
gid:
- contree_sdk.files.prepare_file_tree(source, destination='/', *, exclude=(), uid=0, gid=0, mode=None)[source]¶
Expand directory contents into regular files in stable relative-path order.
Patterns match POSIX relative paths, or basenames when they contain no slash. Excluded directories are pruned. Symlinks and special files raise ValueError. Empty directories cannot be represented by spawn attachments and are omitted. mode=None preserves permission bits; ownership defaults to uid=gid=0.
- Return type:
list[UploadFileSpec]- Returns:
Prepared attachments in relative-path order.
- Raises:
ValueError – The source is not a directory, or an included entry is not a regular file or directory.