Files
files
Service class for handling file operations in Kaleidoscope.
This module provides methods for downloading files from the Kaleidoscope API.
Classes:
| Name | Description |
|---|---|
FilesService |
Service for downloading files by ID. |
Example
path = client.files.download_file(
file_id="file-uuid",
filename="original_filename.csv",
destination="/tmp/downloads",
activity_id="activity-uuid",
)
FilesService
FilesService(client: KaleidoscopeClient)
Service class for file operations.
Provides methods to download files by ID from the Kaleidoscope API.
Methods:
| Name | Description |
|---|---|
download_file |
Download a file by ID and save it to a local path. |
Source code in kalbio/files.py
34 35 | |
download_file
download_file(file_id: str, filename: str | None = None, destination: str | Path | None = None, activity_id: str | None = None) -> str | None
Download a file by ID and save it to a local path.
When activity_id is provided, the download is scoped to that
activity using /activities/{activity_id}/file/{file_id}.
Otherwise falls back to /files/{file_id}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_id
|
str
|
The ID of the file to download. |
required |
filename
|
str
|
Name to save the file as. Defaults to
the file_id if not provided. Typically the |
None
|
destination
|
str | Path
|
Directory to save the file in. Defaults to the current working directory. |
None
|
activity_id
|
str
|
The activity ID to scope the download to. When provided, uses the activity-scoped endpoint. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
The path to the downloaded file on success, |
str | None
|
or None on failure. |
Example
# Download scoped to an activity
path = client.files.download_file(
"file-uuid",
filename="data.csv",
activity_id="activity-uuid",
)
# Download by file ID only
path = client.files.download_file(
"file-uuid",
filename="data.csv",
destination="/tmp/downloads",
)
Source code in kalbio/files.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |