download_object#

torch_brain.utils.s3.download_object(bucket, key, target_path, *, redownload=False, s3_client=None)[source]#

Download a single S3 object to a local file.

Parameters:
  • bucket (str) – S3 bucket name

  • key (str) – Object key to download

  • target_path (Path) – Local file path to write to

  • redownload (bool) – If False (default), return an existing local file as-is. If True, re-download and overwrite any existing local file. If the object is missing on S3, any existing local file is removed.

  • s3_client (Optional[BaseClient]) – Optional pre-configured S3 client

Return type:

Path | None

Returns:

Path to the downloaded or existing local file, or None if the object does not exist on S3.

Raises:
  • RuntimeError – If the download fails for a reason other than the object being absent.

  • ImportError – If boto3/botocore is not installed.