phidown.s5cmd_utils

Attributes

logger

download

Functions

_strip_wrapping_quotes(value) → str

Remove matching wrapping single/double quotes from a token.

_split_command_args(command[, platform_name]) → List[str]

Split an s5cmd command string into args with platform-aware parsing.

_s5cmd_executable() → str

Return the s5cmd command, also when its environment is not activated.

run_s5cmd_with_config(command[, config_file, ...]) → str

Run s5cmd command with configuration file.

_compute_backoff_delay(attempt_index, backoff_base, ...) → float

Compute retry delay with exponential backoff and jitter.

ensure_s5cmd_config(config_file[, reset]) → None

Ensure the s5cmd credential file exists, optionally recreating it.

get_directory_size(directory) → int

Calculate total size of all files in a directory recursively.

pull_down(s3_path[, output_dir, config_file, ...]) → bool

Download Sentinel-1 SAFE directory from Copernicus Data Space.

Module Contents

phidown.s5cmd_utils.logger[source]
phidown.s5cmd_utils._strip_wrapping_quotes(value: str) → str[source]

Remove matching wrapping single/double quotes from a token.

phidown.s5cmd_utils._split_command_args(command: str, platform_name: str | None = None) → List[str][source]

Split an s5cmd command string into args with platform-aware parsing.

On Windows (nt), shlex with posix=False correctly handles backslashes in paths. We then strip wrapping quotes from each token.

phidown.s5cmd_utils._s5cmd_executable() → str[source]

Return the s5cmd command, also when its environment is not activated.

A notebook kernel or a direct .venv/bin/python call does not put the environment’s scripts on PATH.

phidown.s5cmd_utils.run_s5cmd_with_config(command: str | Sequence[str], config_file: str = '.s5cfg', endpoint_url: str | None = None, verbose: bool = False, s5cmd_retry_count: int | None = None, max_workers: int | None = None, log_tail_lines: int = 40) → str[source]

Run s5cmd command with configuration file.

This function executes s5cmd commands using credentials from a configuration file and handles endpoint URL configuration for the Copernicus Data Space.

Parameters:
  • command – The s5cmd command to execute (without ‘s5cmd’ prefix). Can be a shell-like string (e.g. "cp s3://... /tmp/out/") or a sequence of already-split args (e.g. ["cp", "s3://...", "/tmp/out/"]).

  • config_file – Path to s5cmd configuration file (default: ‘.s5cfg’)

  • endpoint_url – Optional endpoint URL override

  • verbose – Whether to print command being executed

  • s5cmd_retry_count – Optional s5cmd internal retry count (global flag).

  • max_workers – Optional s5cmd worker count (global flag).

  • log_tail_lines – Number of trailing output lines to keep in error context.

Returns:

Command output as string

Return type:

str

Raises:

Example

>>> output = run_s5cmd_with_config('ls s3://eodata/Sentinel-1/')
phidown.s5cmd_utils._compute_backoff_delay(attempt_index: int, backoff_base: float, backoff_max: float) → float[source]

Compute retry delay with exponential backoff and jitter.

phidown.s5cmd_utils.ensure_s5cmd_config(config_file: str, reset: bool = False) → None[source]

Ensure the s5cmd credential file exists, optionally recreating it.

phidown.s5cmd_utils.get_directory_size(directory: str) → int[source]

Calculate total size of all files in a directory recursively.

Parameters:

directory – Path to the directory

Returns:

Total size in bytes

Return type:

int

phidown.s5cmd_utils.pull_down(s3_path: str, output_dir: str = '.', config_file: str = '.s5cfg', endpoint_url: str = 'https://eodata.dataspace.copernicus.eu', download_all: bool = True, reset: bool = False, total_size: int | None = None, show_progress: bool = True, retry_count: int = 1, s5cmd_retry_count: int | None = None, max_workers: int | None = None, backoff_base: float = 2.0, backoff_max: float = 60.0) → bool[source]

Download Sentinel-1 SAFE directory from Copernicus Data Space.

This function downloads either individual files or entire SAFE directories from the Copernicus Data Space Ecosystem using the optimized s5cmd tool. Optionally displays a progress bar based on downloaded file size.

Parameters:
  • s3_path – S3 path to the Sentinel-1 data (should start with /eodata/)

  • output_dir – Local output directory for downloaded files

  • config_file – Path to s5cmd configuration file

  • endpoint_url – Copernicus Data Space endpoint URL

  • download_all – If True, downloads entire directory with wildcard pattern

  • reset – If True, prompts for new AWS credentials and resets config file

  • total_size – Expected total size in bytes (for progress bar)

  • show_progress – If True and total_size provided, shows tqdm progress bar

  • retry_count – Number of command-level retries on failure.

  • s5cmd_retry_count – Optional s5cmd internal retry count.

  • max_workers – Optional s5cmd worker count.

  • backoff_base – Base delay in seconds for exponential backoff.

  • backoff_max – Max delay in seconds for exponential backoff.

Returns:

True if download was successful

Return type:

bool

Raises:

Example

>>> # Download entire SAFE directory with progress bar
>>> output = pull_down(
...     '/eodata/Sentinel-1/SAR/IW_RAW__0S/2024/05/03/'
...     'S1A_IW_RAW__0SDV_20240503T031926_20240503T031942_053701_0685FB_E003.SAFE',
...     output_dir='/path/to/data',
...     total_size=1073741824,  # 1 GB
...     show_progress=True
... )

Notes

  • s5cmd is executed as a subprocess and its stdout/stderr are streamed in real time to the logger. This means when pull_down runs you will see file copy progress and status messages as they happen.

  • Ensure s5cmd is installed and available on PATH. There is no additional environment variable required to enable streaming; it’s handled by this function.

  • Progress bar monitors actual disk usage and updates in real-time.

phidown.s5cmd_utils.download[source]