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