Skip to content

Assets Api Wrapped

immichpy.client.wrapper.assets_api_wrapped.AssetsApiWrapped

AssetsApiWrapped(api_client=None)

Bases: AssetsApi

Wrapper for the AssetsApi that provides convenience methods.

Source code in immichpy/client/generated/api/assets_api.py
82
83
84
85
def __init__(self, api_client=None) -> None:
    if api_client is None:
        api_client = ApiClient.get_default()
    self.api_client = api_client

download_asset_to_file async

download_asset_to_file(id: UUID, out_dir: Path, key: StrictStr | None = None, slug: StrictStr | None = None, filename: str | None = None, show_progress: bool = False, **kwargs: Any) -> Path

Download an asset to a file.

Parameters:

Name Type Description Default
id UUID

The asset ID.

required
out_dir Path

The directory to write the asset to.

required
key StrictStr | None

Public share key (the last path segment of a public share URL, i.e. /share/<key>). When provided, the asset can be accessed via the public share link without an API key. Typically you pass either key or slug.

None
slug StrictStr | None

Public share slug for custom share URLs (the last path segment of /s/<slug>). Allows access without authentication. Typically you pass either slug or key.

None
filename str | None

The filename to use. If not provided, we use the original filename from the headers or default to "orig-" + asset_id.

None
show_progress bool

Whether to show a progress bar while downloading.

False
kwargs Any

Additional arguments to pass to the download_asset_without_preload_content method.

{}

Returns:

Type Description
Path

The path to the downloaded file.

For exact request/response behavior, inspect AssetsApi.download_asset_without_preload_content in the generated client.

Source code in immichpy/client/wrapper/assets_api_wrapped.py
27
28
29
30
31
32
33
34
35
36
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
async def download_asset_to_file(
    self,
    id: UUID,
    out_dir: Path,
    key: StrictStr | None = None,
    slug: StrictStr | None = None,
    filename: str | None = None,
    show_progress: bool = False,
    **kwargs: Any,
) -> Path:
    """
    Download an asset to a file.

    :param id: The asset ID.
    :param out_dir: The directory to write the asset to.
    :param key: Public share key (the last path segment of a public share URL, i.e. `/share/<key>`). When provided, the asset can be accessed via the public share link without an API key. Typically you pass either `key` or `slug`.
    :param slug: Public share slug for custom share URLs (the last path segment of `/s/<slug>`). Allows access without authentication. Typically you pass either `slug` or `key`.
    :param filename: The filename to use. If not provided, we use the original filename from the headers or default to "orig-" + asset_id.
    :param show_progress: Whether to show a progress bar while downloading.
    :param kwargs: Additional arguments to pass to the `download_asset_without_preload_content` method.
    :return: The path to the downloaded file.

    For exact request/response behavior, inspect `AssetsApi.download_asset_without_preload_content`
    in the generated client.
    """
    out_dir.mkdir(parents=True, exist_ok=True)

    def make_request(extra_headers: HeadersType | None):
        return self.download_asset_without_preload_content(
            id=id,
            key=key,
            slug=slug,
            _headers=kwargs.get("_headers", {}) | (extra_headers or {}),
            **kwargs,
        )

    return await download_file(
        make_request=make_request,
        out_dir=out_dir,
        resolve_filename=lambda headers: resolve_output_filename(
            headers,
            name=filename,
            default_base=f"orig-{id}",
        ),
        show_progress=show_progress,
    )

play_asset_video_to_file async

play_asset_video_to_file(id: UUID, out_dir: Path, key: StrictStr | None = None, slug: StrictStr | None = None, filename: str | None = None, show_progress: bool = False, **kwargs: Any) -> Path

Save an asset's video stream to a file.

Parameters:

Name Type Description Default
id UUID

The asset ID.

required
out_dir Path

The directory to write the video to.

required
key StrictStr | None

Public share key (the last path segment of a public share URL, i.e. /share/<key>). When provided, the asset can be accessed via the public share link without an API key. Typically you pass either key or slug.

None
slug StrictStr | None

Public share slug for custom share URLs (the last path segment of /s/<slug>). Allows access without authentication. Typically you pass either slug or key.

None
filename str | None

The filename to use. If not provided, we use the original filename from the headers or default to "video-" + asset_id.

None
show_progress bool

Whether to show a progress bar while downloading.

False
kwargs Any

Additional arguments to pass to the [AssetsApi.play_asset_video_without_preload_content][] method.

{}

Returns:

Type Description
Path

The path to the downloaded file.

Source code in immichpy/client/wrapper/assets_api_wrapped.py
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
async def play_asset_video_to_file(
    self,
    id: UUID,
    out_dir: Path,
    key: StrictStr | None = None,
    slug: StrictStr | None = None,
    filename: str | None = None,
    show_progress: bool = False,
    **kwargs: Any,
) -> Path:
    """
    Save an asset's video stream to a file.

    :param id: The asset ID.
    :param out_dir: The directory to write the video to.
    :param key: Public share key (the last path segment of a public share URL, i.e. `/share/<key>`). When provided, the asset can be accessed via the public share link without an API key. Typically you pass either `key` or `slug`.
    :param slug: Public share slug for custom share URLs (the last path segment of `/s/<slug>`). Allows access without authentication. Typically you pass either `slug` or `key`.
    :param filename: The filename to use. If not provided, we use the original filename from the headers or default to "video-" + asset_id.
    :param show_progress: Whether to show a progress bar while downloading.
    :param kwargs: Additional arguments to pass to the [AssetsApi.play_asset_video_without_preload_content][] method.
    :return: The path to the downloaded file.
    """
    out_dir.mkdir(parents=True, exist_ok=True)

    def make_request(extra_headers: HeadersType | None):
        return self.play_asset_video_without_preload_content(
            id=id,
            key=key,
            slug=slug,
            _headers=kwargs.get("_headers", {}) | (extra_headers or {}),
            **kwargs,
        )

    return await download_file(
        make_request=make_request,
        out_dir=out_dir,
        resolve_filename=lambda headers: resolve_output_filename(
            headers,
            name=filename,
            default_base=f"video-{id}",
        ),
        show_progress=show_progress,
    )

upload async

upload(paths: Path | list[Path] | str | list[str], *, ignore_pattern: str | None = None, include_hidden: bool = False, skip_duplicates: bool = False, concurrency: int = 5, show_progress: bool = False, album_name: str | None = None, delete_uploads: bool = False, delete_duplicates: bool = False, dry_run: bool = False) -> UploadResult

Upload assets with smart features (duplicate detection, album management, sidecar support, dry run).

Parameters:

Name Type Description Default
paths Path | list[Path] | str | list[str]

File or directory paths to upload. Can be a single path or list of paths. Directories are automatically walked recursively. To ignore subdirectories, use the ignore_pattern parameter.

required
ignore_pattern str | None

Wildcard pattern to ignore files (uses fnmatch stdlib module, not regex). Examples: ".tmp" (ignore all .tmp files), "/subdir/*" (ignore files in subdir at any level).

None
include_hidden bool

Whether to include hidden files (starting with ".").

False
skip_duplicates bool

Whether to skip duplicate checking (might still get rejected on the server).

False
concurrency int

Number of concurrent uploads. Defaults to 5. A higher number may increase upload speed, but also increases the risk of rate limiting or other issues.

5
show_progress bool

Whether to show progress bars.

False
album_name str | None

Album name to create or use. If None, no album operations are performed.

None
delete_uploads bool

Whether to delete successfully uploaded files locally.

False
delete_duplicates bool

Whether to delete duplicate files locally.

False
dry_run bool

Simulate uploads without actually uploading.

False

Returns:

Type Description
UploadResult

UploadResult with uploaded assets, rejected files, failures, and statistics.

Source code in immichpy/client/wrapper/assets_api_wrapped.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
async def upload(
    self,
    paths: Path | list[Path] | str | list[str],
    *,
    ignore_pattern: str | None = None,
    include_hidden: bool = False,
    skip_duplicates: bool = False,
    concurrency: int = 5,
    show_progress: bool = False,
    album_name: str | None = None,
    delete_uploads: bool = False,
    delete_duplicates: bool = False,
    dry_run: bool = False,
) -> UploadResult:
    """
    Upload assets with smart features (duplicate detection, album management, sidecar support, dry run).

    :param paths: File or directory paths to upload. Can be a single path or list of paths. Directories are automatically walked recursively. To ignore subdirectories, use the `ignore_pattern` parameter.
    :param ignore_pattern: Wildcard pattern to ignore files (uses `fnmatch` stdlib module, not regex). Examples: "*.tmp" (ignore all .tmp files), "*/subdir/*" (ignore files in subdir at any level).
    :param include_hidden: Whether to include hidden files (starting with ".").
    :param skip_duplicates: Whether to skip duplicate checking (might still get rejected on the server).
    :param concurrency: Number of concurrent uploads. Defaults to 5. A higher number may increase upload speed, but also increases the risk of rate limiting or other issues.
    :param show_progress: Whether to show progress bars.
    :param album_name: Album name to create or use. If None, no album operations are performed.
    :param delete_uploads: Whether to delete successfully uploaded files locally.
    :param delete_duplicates: Whether to delete duplicate files locally.
    :param dry_run: Simulate uploads without actually uploading.
    :return: UploadResult with uploaded assets, rejected files, failures, and statistics.
    """
    if concurrency < 1:
        raise ValueError("concurrency must be >= 1")
    server_api = ServerApi(self.api_client)
    albums_api = AlbumsApi(self.api_client)

    _paths = [paths] if isinstance(paths, (str, Path)) else paths
    _paths = [Path(p) for p in _paths]

    files = await scan_files(_paths, server_api, ignore_pattern, include_hidden)
    if not files:
        return UploadResult(
            uploaded=[],
            rejected=[],
            failed=[],
            stats=UploadStats(total=0, uploaded=0, rejected=0, failed=0),
        )

    new_files, checked_rejected = await check_dupes(
        files=files,
        assets_api=self,
        skip_duplicates=skip_duplicates,
        show_progress=show_progress,
        dry_run=dry_run,
    )

    uploaded, actual_rejected, failed = await upload_files(
        files=new_files,
        assets_api=self,
        concurrency=concurrency,
        show_progress=show_progress,
        dry_run=dry_run,
    )

    if album_name and not dry_run:
        await update_albums(
            uploaded=uploaded, album_name=album_name, albums_api=albums_api
        )

    # we can either check pre-upload rejected files or on-upload rejected files, so we return the appropriate list
    # alternative would be to use both lists and deduplicate by asset_id, however adds overhead and assumes the API returned different results
    rejected = actual_rejected if skip_duplicates else checked_rejected

    await delete_files(
        uploaded=uploaded,
        rejected=rejected,
        delete_uploads=delete_uploads,
        delete_duplicates=delete_duplicates,
        dry_run=dry_run,
    )

    return UploadResult(
        uploaded=uploaded,
        rejected=rejected,
        failed=failed,
        stats=UploadStats(
            total=len(files),
            uploaded=len(uploaded),
            rejected=len(rejected),
            failed=len(failed),
        ),
    )

view_asset_to_file async

view_asset_to_file(id: UUID, out_dir: Path, key: StrictStr | None = None, size: AssetMediaSize | None = None, slug: StrictStr | None = None, filename: str | None = None, show_progress: bool = False, **kwargs: Any) -> Path

Save an asset's thumbnail to a file.

Parameters:

Name Type Description Default
id UUID

The asset ID.

required
out_dir Path

The directory to write the asset to.

required
key StrictStr | None

Public share key (the last path segment of a public share URL, i.e. /share/<key>). When provided, the thumbnail can be fetched via the public share link without an API key. Typically you pass either key or slug.

None
size AssetMediaSize | None

Thumbnail size.

None
slug StrictStr | None

Public share slug for custom share URLs (the last path segment of /s/<slug>). Allows access without authentication. Typically you pass either slug or key.

None
filename str | None

The filename to use. If not provided, we use the original filename from the headers or default to "thumb-" + asset_id.

None
show_progress bool

Whether to show a progress bar while downloading.

False
kwargs Any

Additional arguments to pass to the [AssetsApi.view_asset_without_preload_content][] method.

{}

Returns:

Type Description
Path

The path to the downloaded file.

Source code in immichpy/client/wrapper/assets_api_wrapped.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
async def view_asset_to_file(
    self,
    id: UUID,
    out_dir: Path,
    key: StrictStr | None = None,
    size: AssetMediaSize | None = None,
    slug: StrictStr | None = None,
    filename: str | None = None,
    show_progress: bool = False,
    **kwargs: Any,
) -> Path:
    """
    Save an asset's thumbnail to a file.

    :param id: The asset ID.
    :param out_dir: The directory to write the asset to.
    :param key: Public share key (the last path segment of a public share URL, i.e. `/share/<key>`). When provided, the thumbnail can be fetched via the public share link without an API key. Typically you pass either `key` or `slug`.
    :param size: Thumbnail size.
    :param slug: Public share slug for custom share URLs (the last path segment of `/s/<slug>`). Allows access without authentication. Typically you pass either `slug` or `key`.
    :param filename: The filename to use. If not provided, we use the original filename from the headers or default to "thumb-" + asset_id.
    :param show_progress: Whether to show a progress bar while downloading.
    :param kwargs: Additional arguments to pass to the [AssetsApi.view_asset_without_preload_content][] method.
    :return: The path to the downloaded file.
    """
    out_dir.mkdir(parents=True, exist_ok=True)

    def make_request(extra_headers: HeadersType | None):
        return self.view_asset_without_preload_content(
            id=id,
            key=key,
            size=size,
            slug=slug,
            _headers=kwargs.get("_headers", {}) | (extra_headers or {}),
            **kwargs,
        )

    return await download_file(
        make_request=make_request,
        out_dir=out_dir,
        resolve_filename=lambda headers: resolve_output_filename(
            headers,
            name=filename,
            default_base=f"thumb-{id}",
        ),
        show_progress=show_progress,
    )