Source code for multistorageclient.client.client

  1# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
  2# SPDX-License-Identifier: Apache-2.0
  3#
  4# Licensed under the Apache License, Version 2.0 (the "License");
  5# you may not use this file except in compliance with the License.
  6# You may obtain a copy of the License at
  7#
  8# http://www.apache.org/licenses/LICENSE-2.0
  9#
 10# Unless required by applicable law or agreed to in writing, software
 11# distributed under the License is distributed on an "AS IS" BASIS,
 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13# See the License for the specific language governing permissions and
 14# limitations under the License.
 15
 16import logging
 17from collections.abc import Iterator, Sequence
 18from typing import IO, Any, Optional, Union
 19
 20from ..config import StorageClientConfig
 21from ..constants import MEMORY_LOAD_LIMIT
 22from ..file import ObjectFile, PosixFile
 23from ..types import (
 24    ExecutionMode,
 25    MetadataProvider,
 26    ObjectMetadata,
 27    PatternList,
 28    Range,
 29    SignerType,
 30    SourceVersionCheckMode,
 31    StorageProvider,
 32    SymlinkHandling,
 33    SyncResult,
 34)
 35from .composite import CompositeStorageClient
 36from .single import SingleStorageClient
 37from .types import AbstractStorageClient
 38
 39logger = logging.getLogger(__name__)
 40
 41
[docs] 42class StorageClient(AbstractStorageClient): 43 """ 44 Unified storage client facade. 45 46 Automatically delegates to: 47 - SingleStorageClient: For single-backend configurations (full read/write) 48 - CompositeStorageClient: For multi-backend configurations (read-only) 49 """ 50 51 _delegate: Union[SingleStorageClient, CompositeStorageClient] 52 53 def __init__(self, config: StorageClientConfig): 54 if config.storage_provider_profiles: 55 self._delegate = CompositeStorageClient(config) 56 logger.debug(f"StorageClient '{config.profile}' using CompositeStorageClient (read-only)") 57 else: 58 self._delegate = SingleStorageClient(config) 59 logger.debug(f"StorageClient '{config.profile}' using SingleStorageClient") 60 61 @property 62 def delegate(self) -> Union[SingleStorageClient, CompositeStorageClient]: 63 """ 64 Access to underlying delegate storage client. 65 66 :return: SingleStorageClient or CompositeStorageClient. 67 """ 68 return self._delegate 69 70 @property 71 def _config(self) -> StorageClientConfig: 72 """ 73 :return: The configuration for the underlying storage client. 74 """ 75 return self._delegate._config 76 77 @property 78 def _storage_provider(self) -> Optional[StorageProvider]: 79 """ 80 :return: The storage provider for the underlying storage client. None for CompositeStorageClient. 81 """ 82 return self._delegate._storage_provider 83 84 @_storage_provider.setter 85 def _storage_provider(self, value: StorageProvider) -> None: 86 """Allow mutation of storage provider for testing purposes.""" 87 if isinstance(self._delegate, SingleStorageClient): 88 self._delegate._storage_provider = value 89 90 @property 91 def _metadata_provider(self) -> Optional[MetadataProvider]: 92 """ 93 :return: The metadata provider for the underlying storage client. 94 """ 95 return self._delegate._metadata_provider 96 97 @_metadata_provider.setter 98 def _metadata_provider(self, value: Optional[MetadataProvider]) -> None: 99 """Allow mutation of metadata provider for DSS compatibility.""" 100 if isinstance(self._delegate, CompositeStorageClient) and value is None: 101 raise ValueError("CompositeStorageClient requires a metadata_provider for routing decisions.") 102 self._delegate._metadata_provider = value # type: ignore[assignment] 103 104 @property 105 def _metadata_provider_lock(self): 106 """ 107 Access to metadata provider lock for DSS compatibility. 108 109 :return: The lock for the metadata provider. 110 """ 111 return self._delegate._metadata_provider_lock 112 113 @_metadata_provider_lock.setter 114 def _metadata_provider_lock(self, value): 115 """Allow mutation of metadata provider lock for DSS compatibility.""" 116 self._delegate._metadata_provider_lock = value 117 118 @property 119 def _credentials_provider(self): 120 """ 121 :return: The credentials provider for the underlying storage client. 122 """ 123 return self._delegate._credentials_provider 124 125 @property 126 def _retry_config(self): 127 """ 128 :return: The retry configuration for the underlying storage client. 129 """ 130 return self._delegate._retry_config 131 132 @property 133 def _cache_manager(self): 134 """ 135 :return: The cache manager for the underlying storage client. 136 """ 137 return self._delegate._cache_manager 138 139 @property 140 def _replica_manager(self): 141 """ 142 :return: The replica manager for the underlying storage client. 143 """ 144 return self._delegate._replica_manager 145 146 @_replica_manager.setter 147 def _replica_manager(self, value): 148 """ 149 Allow mutation of replica manager for testing purposes. 150 151 :param value: The new replica manager. 152 """ 153 if isinstance(self._delegate, SingleStorageClient): 154 self._delegate._replica_manager = value 155 156 @property 157 def profile(self) -> str: 158 """ 159 :return: The profile name of the storage client. 160 """ 161 return self._delegate.profile 162 163 @property 164 def replicas(self) -> list[AbstractStorageClient]: 165 """ 166 :return: List of replica storage clients, sorted by read priority. 167 """ 168 return self._delegate.replicas 169
[docs] 170 def is_default_profile(self) -> bool: 171 """ 172 :return: ``True`` if the storage client is using the default profile, ``False`` otherwise. 173 """ 174 return self._delegate.is_default_profile()
175 176 def _is_rust_client_enabled(self) -> bool: 177 """ 178 :return: ``True`` if the storage provider is using the Rust client, ``False`` otherwise. 179 """ 180 return self._delegate._is_rust_client_enabled() 181 182 def _is_posix_file_storage_provider(self) -> bool: 183 """ 184 :return: ``True`` if the storage client is using a POSIX file storage provider, ``False`` otherwise. 185 """ 186 return self._delegate._is_posix_file_storage_provider() 187
[docs] 188 def get_posix_path(self, path: str) -> Optional[str]: 189 """ 190 Returns the physical POSIX filesystem path for POSIX storage providers. 191 192 :param path: The path to resolve (may be a symlink or virtual path). 193 :return: Physical POSIX filesystem path if POSIX storage, None otherwise. 194 """ 195 return self._delegate.get_posix_path(path)
196
[docs] 197 def read( 198 self, 199 path: str, 200 byte_range: Optional[Range] = None, 201 check_source_version: SourceVersionCheckMode = SourceVersionCheckMode.INHERIT, 202 ) -> bytes: 203 """ 204 Read bytes from a file at the specified logical path. 205 206 :param path: The logical path of the object to read. 207 :param byte_range: Optional byte range to read (offset and length). 208 :param check_source_version: Whether to check the source version of cached objects. 209 :return: The content of the object as bytes. 210 :raises FileNotFoundError: If the file at the specified path does not exist. 211 """ 212 return self._delegate.read(path, byte_range, check_source_version)
213
[docs] 214 def open( 215 self, 216 path: str, 217 mode: str = "rb", 218 buffering: int = -1, 219 encoding: Optional[str] = None, 220 disable_read_cache: bool = False, 221 memory_load_limit: int = MEMORY_LOAD_LIMIT, 222 atomic: bool = True, 223 check_source_version: SourceVersionCheckMode = SourceVersionCheckMode.INHERIT, 224 attributes: Optional[dict[str, Any]] = None, 225 prefetch_file: Optional[bool] = None, 226 ) -> Union[PosixFile, ObjectFile]: 227 """ 228 Open a file for reading or writing. 229 230 :param path: The logical path of the object to open. 231 :param mode: The file mode. Supported modes: "r", "rb", "w", "wb", "a", "ab". 232 :param buffering: The buffering mode. Only applies to PosixFile. 233 :param encoding: The encoding to use for text files. 234 :param disable_read_cache: When set to ``True``, disables caching for file content. 235 This parameter is only applicable to ObjectFile when the mode is "r" or "rb". 236 :param memory_load_limit: Size limit in bytes for loading files into memory. Defaults to 512MB. 237 This parameter is only applicable to ObjectFile when the mode is "r" or "rb". Defaults to 512MB. 238 :param atomic: When set to ``True``, file will be written atomically (rename upon close). 239 This parameter is only applicable to PosixFile in write mode. 240 :param check_source_version: Whether to check the source version of cached objects. 241 :param attributes: Attributes to add to the file. 242 This parameter is only applicable when the mode is "w" or "wb" or "a" or "ab". Defaults to None. 243 :param prefetch_file: Whether to prefetch the file content. 244 This parameter is only applicable to ObjectFile when the mode is "r" or "rb". 245 If None, inherits from cache configuration. 246 :return: A file-like object (PosixFile or ObjectFile) for the specified path. 247 :raises FileNotFoundError: If the file does not exist (read mode). 248 :raises NotImplementedError: If the operation is not supported (e.g., write on CompositeStorageClient). 249 """ 250 return self._delegate.open( 251 path, 252 mode, 253 buffering, 254 encoding, 255 disable_read_cache, 256 memory_load_limit, 257 atomic, 258 check_source_version, 259 attributes, 260 prefetch_file, 261 )
262
[docs] 263 def download_file(self, remote_path: str, local_path: Union[str, IO]) -> None: 264 """ 265 Download a remote file to a local path or file-like object. 266 267 :param remote_path: The logical path of the remote file to download. 268 :param local_path: The local file path or file-like object to write to. 269 :raises FileNotFoundError: If the remote file does not exist. 270 """ 271 return self._delegate.download_file(remote_path, local_path)
272
[docs] 273 def download_files( 274 self, 275 remote_paths: list[str], 276 local_paths: list[str], 277 metadata: Optional[Sequence[Optional[ObjectMetadata]]] = None, 278 max_workers: int = 16, 279 ) -> None: 280 """ 281 Download multiple remote files to local paths. 282 283 :param remote_paths: List of logical paths of remote files to download. 284 :param local_paths: List of local file paths to save the downloaded files to. 285 :param metadata: Optional per-file metadata used to decide between regular and multipart download. 286 :param max_workers: Maximum number of concurrent download workers (default: 16). 287 :raises ValueError: If remote_paths and local_paths have different lengths. 288 :raises FileNotFoundError: If any remote file does not exist. 289 """ 290 return self._delegate.download_files(remote_paths, local_paths, metadata, max_workers)
291
[docs] 292 def glob( 293 self, 294 pattern: str, 295 include_url_prefix: bool = False, 296 attribute_filter_expression: Optional[str] = None, 297 ) -> list[str]: 298 """ 299 Matches and retrieves a list of object keys in the storage provider that match the specified pattern. 300 301 :param pattern: The pattern to match object keys against, supporting wildcards (e.g., ``*.txt``). 302 :param include_url_prefix: Whether to include the URL prefix ``msc://profile`` in the result. 303 :param attribute_filter_expression: The attribute filter expression to apply to the result. 304 :return: A list of object paths that match the specified pattern. 305 """ 306 return self._delegate.glob(pattern, include_url_prefix, attribute_filter_expression)
307
[docs] 308 def list_recursive( 309 self, 310 path: str = "", 311 start_after: Optional[str] = None, 312 end_at: Optional[str] = None, 313 max_workers: int = 32, 314 look_ahead: int = 2, 315 include_url_prefix: bool = False, 316 patterns: Optional[PatternList] = None, 317 symlink_handling: SymlinkHandling = SymlinkHandling.FOLLOW, 318 ) -> Iterator[ObjectMetadata]: 319 """ 320 List files recursively in the storage provider under the specified path. 321 322 :param path: The directory or file path to list objects under. This should be a 323 complete filesystem path (e.g., "my-bucket/documents/" or "data/2024/"). 324 :param start_after: The key to start after (i.e. exclusive). An object with this key doesn't have to exist. 325 :param end_at: The key to end at (i.e. inclusive). An object with this key doesn't have to exist. 326 :param max_workers: Maximum concurrent workers for provider-level recursive listing. 327 :param look_ahead: Prefixes to buffer per worker for provider-level recursive listing. 328 :param include_url_prefix: Whether to include the URL prefix ``msc://profile`` in the result. 329 :param patterns: PatternList for include/exclude filtering. If None, all files are included. 330 :param symlink_handling: How to handle symbolic links during listing. Only applicable for POSIX file storage providers. 331 :return: An iterator over ObjectMetadata for matching files. 332 """ 333 return self._delegate.list_recursive( 334 path=path, 335 start_after=start_after, 336 end_at=end_at, 337 max_workers=max_workers, 338 look_ahead=look_ahead, 339 include_url_prefix=include_url_prefix, 340 patterns=patterns, 341 symlink_handling=symlink_handling, 342 )
343
[docs] 344 def is_file(self, path: str) -> bool: 345 """ 346 Checks whether the specified path points to a file (rather than a folder or directory). 347 348 :param path: The logical path to check. 349 :return: ``True`` if the key points to a file, ``False`` otherwise. 350 """ 351 return self._delegate.is_file(path)
352
[docs] 353 def is_empty(self, path: str) -> bool: 354 """ 355 Check whether the specified path is empty. A path is considered empty if there are no 356 objects whose keys start with the given path as a prefix. 357 358 :param path: The logical path to check (typically a directory or folder prefix). 359 :return: ``True`` if no objects exist under the specified path prefix, ``False`` otherwise. 360 """ 361 return self._delegate.is_empty(path)
362
[docs] 363 def info(self, path: str, strict: bool = True) -> ObjectMetadata: 364 """ 365 Get metadata for a file at the specified path. 366 367 :param path: The logical path of the object. 368 :param strict: When ``True``, only return committed metadata. When ``False``, include pending changes. 369 :return: ObjectMetadata containing file information (size, last modified, etc.). 370 :raises FileNotFoundError: If the file at the specified path does not exist. 371 """ 372 return self._delegate.info(path, strict)
373
[docs] 374 def write( 375 self, 376 path: str, 377 body: bytes, 378 attributes: Optional[dict[str, Any]] = None, 379 ) -> None: 380 """ 381 Write bytes to a file at the specified path. 382 383 :param path: The logical path where the object will be written. 384 :param body: The content to write as bytes. 385 :param attributes: Optional attributes to add to the file. 386 :raises NotImplementedError: If write operations are not supported (e.g., CompositeStorageClient). 387 """ 388 return self._delegate.write(path, body, attributes)
389
[docs] 390 def delete(self, path: str, recursive: bool = False) -> None: 391 """ 392 Delete a file or directory at the specified path. 393 394 :param path: The logical path of the object to delete. 395 :param recursive: When True, delete directory and all its contents recursively. 396 :raises FileNotFoundError: If the file or directory does not exist. 397 :raises NotImplementedError: If delete operations are not supported (e.g., CompositeStorageClient). 398 """ 399 return self._delegate.delete(path, recursive)
400
[docs] 401 def delete_many(self, paths: list[str]) -> None: 402 """ 403 Delete multiple files at the specified paths. Only files are supported; directories are not deleted. 404 Paths that do not exist are treated as successful no-ops. 405 406 :param paths: List of logical paths of the files to delete. 407 :raises NotImplementedError: If delete operations are not supported (e.g., CompositeStorageClient). 408 """ 409 return self._delegate.delete_many(paths)
410
[docs] 411 def copy(self, src_path: str, dest_path: str) -> None: 412 """ 413 Copy a file from source path to destination path. 414 415 :param src_path: The logical path of the source object. 416 :param dest_path: The logical path where the object will be copied to. 417 :raises FileNotFoundError: If the source file does not exist. 418 :raises NotImplementedError: If copy operations are not supported (e.g., CompositeStorageClient). 419 """ 420 return self._delegate.copy(src_path, dest_path)
421 435
[docs] 436 def upload_file( 437 self, 438 remote_path: str, 439 local_path: Union[str, IO], 440 attributes: Optional[dict[str, Any]] = None, 441 ) -> None: 442 """ 443 Upload a local file to remote storage. 444 445 :param remote_path: The logical path where the file will be uploaded. 446 :param local_path: The local file path or file-like object to upload. 447 :param attributes: Optional attributes to add to the file. 448 :raises FileNotFoundError: If the local file does not exist. 449 :raises NotImplementedError: If upload operations are not supported (e.g., CompositeStorageClient). 450 """ 451 return self._delegate.upload_file(remote_path, local_path, attributes)
452
[docs] 453 def upload_files( 454 self, 455 remote_paths: list[str], 456 local_paths: list[str], 457 attributes: Optional[Sequence[Optional[dict[str, Any]]]] = None, 458 max_workers: int = 16, 459 ) -> None: 460 """ 461 Upload multiple local files to remote storage. 462 463 :param remote_paths: List of logical paths where the files will be uploaded. 464 :param local_paths: List of local file paths to upload. 465 :param attributes: Optional list of per-file attributes to add. When provided, must have the same length 466 as remote_paths/local_paths. Each element may be ``None`` for files that need no attributes. 467 :param max_workers: Maximum number of concurrent upload workers (default: 16). 468 :raises ValueError: If remote_paths and local_paths have different lengths. 469 :raises ValueError: If attributes is provided and has a different length than remote_paths. 470 :raises NotImplementedError: If upload operations are not supported (e.g., CompositeStorageClient). 471 """ 472 return self._delegate.upload_files(remote_paths, local_paths, attributes, max_workers)
473
[docs] 474 def commit_metadata(self, prefix: Optional[str] = None) -> None: 475 """ 476 Commits any pending updates to the metadata provider. No-op if not using a metadata provider. 477 478 :param prefix: If provided, scans the prefix to find files to commit. 479 """ 480 return self._delegate.commit_metadata(prefix)
481
[docs] 482 def sync_from( 483 self, 484 source_client: AbstractStorageClient, 485 source_path: str = "", 486 target_path: str = "", 487 delete_unmatched_files: bool = False, 488 description: str = "Syncing", 489 num_worker_processes: Optional[int] = None, 490 execution_mode: ExecutionMode = ExecutionMode.LOCAL, 491 patterns: Optional[PatternList] = None, 492 preserve_source_attributes: bool = False, 493 source_files: Optional[list[str]] = None, 494 ignore_hidden: bool = True, 495 commit_metadata: bool = True, 496 dryrun: bool = False, 497 dryrun_output_path: Optional[str] = None, 498 symlink_handling: SymlinkHandling = SymlinkHandling.FOLLOW, 499 ) -> SyncResult: 500 """ 501 Syncs files from the source storage client to "path/". 502 503 :param source_client: The source storage client. 504 :param source_path: The logical path to sync from. 505 :param target_path: The logical path to sync to. 506 :param delete_unmatched_files: Whether to delete files at the target that are not present at the source. 507 :param description: Description of sync process for logging purposes. 508 :param num_worker_processes: The number of worker processes to use. 509 :param execution_mode: The execution mode to use. Currently supports "local" and "ray". 510 :param patterns: PatternList for include/exclude filtering. If None, all files are included. 511 Cannot be used together with source_files. 512 :param preserve_source_attributes: Whether to preserve source file metadata attributes during synchronization. 513 When ``False`` (default), only file content is copied. When ``True``, custom metadata attributes are also preserved. 514 515 .. warning:: 516 **Performance Impact**: When enabled without a ``metadata_provider`` configured, this will make a HEAD 517 request for each object to retrieve attributes, which can significantly impact performance on large-scale 518 sync operations. For production use at scale, configure a ``metadata_provider`` in your storage profile. 519 520 :param source_files: Optional list of file paths (relative to source_path) to sync. When provided, only these 521 specific files will be synced, skipping enumeration of the source path. Cannot be used together with patterns. 522 :param ignore_hidden: Whether to ignore hidden files and directories. Default is ``True``. 523 :param commit_metadata: When ``True`` (default), calls :py:meth:`StorageClient.commit_metadata` after sync completes. 524 Set to ``False`` to skip the commit, allowing batching of multiple sync operations before committing manually. 525 :param dryrun: If ``True``, only enumerate and compare objects without performing any copy/delete operations. 526 The returned :py:class:`SyncResult` will include a :py:class:`DryrunResult` with paths to JSONL files. 527 :param dryrun_output_path: Directory to write dryrun JSONL files into. If ``None`` (default), a temporary 528 directory is created automatically. Ignored when ``dryrun`` is ``False``. 529 :param symlink_handling: How to handle symbolic links during sync. 530 :py:attr:`SymlinkHandling.FOLLOW` (default) dereferences symlinks and copies the target's bytes. 531 :py:attr:`SymlinkHandling.SKIP` excludes symlinks from the sync. 532 :py:attr:`SymlinkHandling.PRESERVE` recreates symlinks on the target via :py:meth:`make_symlink` 533 instead of copying bytes (required for round-trip preservation of symlinks). 534 :raises ValueError: If both source_files and patterns are provided. 535 :raises NotImplementedError: If sync operations are not supported (e.g., CompositeStorageClient as target). 536 """ 537 return self._delegate.sync_from( 538 source_client, 539 source_path, 540 target_path, 541 delete_unmatched_files, 542 description, 543 num_worker_processes, 544 execution_mode, 545 patterns, 546 preserve_source_attributes, 547 source_files, 548 ignore_hidden, 549 commit_metadata, 550 dryrun, 551 dryrun_output_path, 552 symlink_handling, 553 )
554
[docs] 555 def sync_replicas( 556 self, 557 source_path: str, 558 replica_indices: Optional[list[int]] = None, 559 delete_unmatched_files: bool = False, 560 description: str = "Syncing replica", 561 num_worker_processes: Optional[int] = None, 562 execution_mode: ExecutionMode = ExecutionMode.LOCAL, 563 patterns: Optional[PatternList] = None, 564 ignore_hidden: bool = True, 565 symlink_handling: SymlinkHandling = SymlinkHandling.FOLLOW, 566 ) -> None: 567 """ 568 Sync files from this client to its replica storage clients. 569 570 :param source_path: The logical path to sync from. 571 :param replica_indices: Specific replica indices to sync to (0-indexed). If None, syncs to all replicas. 572 :param delete_unmatched_files: When set to ``True``, delete files in replicas that don't exist in source. 573 :param description: Description of sync process for logging purposes. 574 :param num_worker_processes: Number of worker processes for parallel sync. 575 :param execution_mode: Execution mode (LOCAL or REMOTE). 576 :param patterns: PatternList for include/exclude filtering. If None, all files are included. 577 :param ignore_hidden: When set to ``True``, ignore hidden files (starting with '.'). Defaults to ``True``. 578 :param symlink_handling: How to handle symbolic links during sync. 579 :py:attr:`SymlinkHandling.FOLLOW` (default) dereferences symlinks and copies the target's bytes. 580 :py:attr:`SymlinkHandling.SKIP` excludes symlinks from the sync. 581 :py:attr:`SymlinkHandling.PRESERVE` recreates symlinks on each replica via 582 :py:meth:`make_symlink` instead of copying bytes. 583 """ 584 return self._delegate.sync_replicas( 585 source_path, 586 replica_indices, 587 delete_unmatched_files, 588 description, 589 num_worker_processes, 590 execution_mode, 591 patterns, 592 ignore_hidden, 593 symlink_handling, 594 )
595
[docs] 596 def list( 597 self, 598 path: str = "", 599 start_after: Optional[str] = None, 600 end_at: Optional[str] = None, 601 include_directories: bool = False, 602 include_url_prefix: bool = False, 603 attribute_filter_expression: Optional[str] = None, 604 show_attributes: bool = False, 605 patterns: Optional[PatternList] = None, 606 symlink_handling: SymlinkHandling = SymlinkHandling.FOLLOW, 607 ) -> Iterator[ObjectMetadata]: 608 """ 609 List objects in the storage provider under the specified path. 610 611 :param path: The directory or file path to list objects under. This should be a 612 complete filesystem path (e.g., "my-bucket/documents/" or "data/2024/"). 613 :param start_after: The key to start after (i.e. exclusive). An object with this key doesn't have to exist. 614 :param end_at: The key to end at (i.e. inclusive). An object with this key doesn't have to exist. 615 :param include_directories: Whether to include directories in the result. When ``True``, directories are returned alongside objects. 616 :param include_url_prefix: Whether to include the URL prefix ``msc://profile`` in the result. 617 :param attribute_filter_expression: The attribute filter expression to apply to the result. 618 :param show_attributes: Whether to return attributes in the result. WARNING: Depending on implementation, there may be a performance impact if this is set to ``True``. 619 :param patterns: PatternList for include/exclude filtering. If None, all files are included. 620 :param symlink_handling: How to handle symbolic links during listing. Only applicable for POSIX file storage providers. 621 :return: An iterator over ObjectMetadata for matching objects. 622 """ 623 return self._delegate.list( 624 path, 625 start_after, 626 end_at, 627 include_directories, 628 include_url_prefix, 629 attribute_filter_expression, 630 show_attributes, 631 patterns=patterns, 632 symlink_handling=symlink_handling, 633 )
634
[docs] 635 def generate_presigned_url( 636 self, 637 path: str, 638 *, 639 method: str = "GET", 640 signer_type: Optional[SignerType] = None, 641 signer_options: Optional[dict[str, Any]] = None, 642 ) -> str: 643 """ 644 Generate a pre-signed URL granting temporary access to the object at *path*. 645 646 :param path: The logical path of the object. 647 :param method: The HTTP method the URL should authorise (e.g. ``"GET"``, ``"PUT"``). 648 :param signer_type: The signing backend to use. ``None`` means the provider's native signer. 649 :param signer_options: Backend-specific options forwarded to the signer. 650 :return: A pre-signed URL string. 651 :raises NotImplementedError: If the underlying storage provider does not support presigned URLs. 652 """ 653 return self._delegate.generate_presigned_url( 654 path, method=method, signer_type=signer_type, signer_options=signer_options 655 )
656 657 def __getstate__(self) -> dict[str, Any]: 658 """Support for pickling (forward to delegate).""" 659 return self._delegate.__getstate__() 660 661 def __setstate__(self, state: dict[str, Any]) -> None: 662 """Support for unpickling - reconstruct the delegate.""" 663 config = state["_config"] 664 665 if config.storage_provider_profiles: 666 self._delegate = CompositeStorageClient.__new__(CompositeStorageClient) 667 self._delegate.__setstate__(state) 668 else: 669 self._delegate = SingleStorageClient.__new__(SingleStorageClient) 670 self._delegate.__setstate__(state)