cursus.steps.utils.s3_utils

class S3PathHandler[source]

Bases: object

Utility class for handling S3 URIs and paths.

Provides methods to properly manipulate S3 paths while avoiding common issues like double slashes or incorrect path handling that can occur when using standard os.path functions with S3 URIs.

static parse_uri(uri)[source]

Parse an S3 URI into components.

Parameters:

uri (str) – S3 URI to parse

Returns:

(bucket, key)

Return type:

tuple

Raises:

ValueError – If not a valid S3 URI

classmethod normalize(uri, description='S3 URI')[source]

Normalize an S3 URI by ensuring no trailing slashes or double slashes.

Parameters:
  • uri (str) – S3 URI to normalize

  • description (str) – Description for logging

Returns:

Normalized S3 URI

Return type:

str

classmethod join(base_uri, *paths)[source]

Join path components with an S3 URI base.

Parameters:
  • base_uri (str) – Base S3 URI

  • *paths (str) – Path components to join

Returns:

Joined S3 URI

Return type:

str

classmethod get_parent(uri)[source]

Get the parent directory of an S3 URI.

Parameters:

uri (str) – S3 URI

Returns:

Parent S3 URI

Return type:

str

classmethod get_name(uri)[source]

Get the basename (filename) of an S3 URI.

Parameters:

uri (str) – S3 URI

Returns:

Basename of the URI

Return type:

str

classmethod ensure_directory(uri, filename=None)[source]

Ensure URI represents a directory path (without filename).

Parameters:
  • uri (str) – S3 URI

  • filename (str) – Optional filename to check for at end

Returns:

Directory path without trailing filename

Return type:

str

classmethod is_valid(uri)[source]

Check if a string is a valid S3 URI.

Parameters:

uri (str) – URI to validate

Returns:

True if valid S3 URI

Return type:

bool