Skip to content

Transfers

Transfers copy files to and from local and remote storage (file, HTTP, S3, Google Cloud Storage, Azure, Oceanum Datamesh). Data objects use them to fetch remote sources.

rompy.transfer.manager

Multi-destination transfer orchestration for ROMPy.

TransferFailurePolicy

Bases: Enum

Policy for handling transfer failures when uploading to multiple destinations.

Attributes:

Name Type Description
CONTINUE

Record failures but continue with remaining transfers

FAIL_FAST

Stop and raise exception on first failure

CONTINUE class-attribute instance-attribute

CONTINUE = 'continue'

FAIL_FAST class-attribute instance-attribute

FAIL_FAST = 'fail_fast'

TransferItemResult dataclass

TransferItemResult(
    local_path: Path,
    dest_prefix: str,
    target_name: str,
    dest_uri: str,
    ok: bool,
    error: Optional[str] = None,
)

Result of transferring a single file to a single destination.

Attributes:

Name Type Description
local_path Path

Source file path on local filesystem

dest_prefix str

Destination prefix (treated as folder-like)

target_name str

Target filename to append to prefix

dest_uri str

Final constructed URI (prefix + target_name)

ok bool

True if transfer succeeded, False otherwise

error Optional[str]

Error message if transfer failed, None if succeeded

local_path instance-attribute

local_path: Path

dest_prefix instance-attribute

dest_prefix: str

target_name instance-attribute

target_name: str

dest_uri instance-attribute

dest_uri: str

ok instance-attribute

ok: bool

error class-attribute instance-attribute

error: Optional[str] = None

TransferBatchResult dataclass

TransferBatchResult(
    total: int,
    succeeded: int,
    failed: int,
    items: list[TransferItemResult] = list(),
)

Aggregated results from transferring files to multiple destinations.

Attributes:

Name Type Description
total int

Total number of transfer attempts

succeeded int

Number of successful transfers

failed int

Number of failed transfers

items list[TransferItemResult]

Detailed per-transfer results

total instance-attribute

total: int

succeeded instance-attribute

succeeded: int

failed instance-attribute

failed: int

items class-attribute instance-attribute

items: list[TransferItemResult] = field(
    default_factory=list
)

all_succeeded

all_succeeded() -> bool

Check if all transfers succeeded.

Returns:

Type Description
bool

True if all transfers succeeded, False otherwise

TransferManager

Orchestrates file transfers to multiple destination prefixes.

Handles fan-out of local files to multiple destinations using rompy.transfer backends, with configurable failure policies and aggregated result tracking.

transfer_files

transfer_files(
    files: list[Path],
    destinations: list[str],
    name_map: dict[Path, str],
    policy: TransferFailurePolicy = CONTINUE,
) -> TransferBatchResult

Transfer multiple files to multiple destination prefixes.

For each file, computes the target name via name_map, then transfers to all destination prefixes. Destinations are treated as prefixes (folder-like), not complete object URIs.

Final destination URI construction

dest_uri = join_prefix(dest_prefix, target_name)

Example

files = [Path("restart.ww3"), Path("output.nc")] destinations = ["s3://bucket/outputs/", "file:///local/backup/"] name_map = { Path("restart.ww3"): "20230101_000000_restart.ww3", Path("output.nc"): "20230101_000000_output.nc" }

Results in transfers to: - s3://bucket/outputs/20230101_000000_restart.ww3 - s3://bucket/outputs/20230101_000000_output.nc - file:///local/backup/20230101_000000_restart.ww3 - file:///local/backup/20230101_000000_output.nc

Parameters:

Name Type Description Default
files list[Path]

List of local file paths to transfer

required
destinations list[str]

List of destination prefixes (e.g., "s3://bucket/path/")

required
name_map dict[Path, str]

Mapping from local path to target filename

required
policy TransferFailurePolicy

Failure handling policy (CONTINUE or FAIL_FAST)

CONTINUE

Returns:

Type Description
TransferBatchResult

TransferBatchResult with aggregated success/failure counts and details

Raises:

Type Description
Exception

On first failure if policy is FAIL_FAST

rompy.transfer.registry

Transfer registry for scheme-based dispatch.

get_registry

get_registry() -> Dict[str, Type['TransferBase']]

Get the cached transfer registry.

Lazy-loads the registry on first access.

get_transfer

get_transfer(
    uri_or_pathlike: Union[str, Path, Any],
) -> "TransferBase"

Get a transfer instance for the given URI or path-like object.

Parameters:

Name Type Description Default
uri_or_pathlike Union[str, Path, Any]

URI string, Path, or cloudpathlib.AnyPath object

required

Returns:

Type Description
'TransferBase'

Instantiated transfer object for the scheme

Raises:

Type Description
KeyError

If no transfer is registered for the URI's scheme

rompy.transfer.base

TransferBase

Bases: ABC

Abstract base class defining the transfer interface for ROMPy. Concrete schemes (e.g., local file, s3, http) will implement these methods.

get abstractmethod

get(
    uri: str,
    destdir: Path,
    name: Optional[str] = None,
    link: bool = False,
) -> Path

Retrieve data from the given URI and place it under destdir. Returns the final Path to the retrieved object.

exists abstractmethod

exists(uri: str) -> bool

Return True if the given URI exists in the transfer store.

list abstractmethod

list(uri: str) -> List[str]

List items under the given URI and return a list of their names/paths.

put abstractmethod

put(local_path: Path, uri: str) -> str

Upload or copy a local file to the given URI. Returns the URI that was created.

delete abstractmethod

delete(uri: str, recursive: bool = False) -> None

Delete the resource at the given URI. If recursive is True, delete recursively.

stat abstractmethod

stat(uri: str) -> Dict[str, Any]

Return a dictionary with metadata about the given URI.

rompy.transfer.file

File transfer implementation for local filesystem operations.

FileTransfer

Bases: TransferBase

Transfer implementation for local file:// scheme and plain file paths.

get

get(
    uri: str,
    destdir: Path,
    name: Optional[str] = None,
    link: bool = False,
) -> Path

Retrieve local file/directory and place it in destdir.

Parameters:

Name Type Description Default
uri str

File URI or path string

required
destdir Path

Destination directory

required
name Optional[str]

Optional name for the destination (default: use source name)

None
link bool

If True, create symlink instead of copy (local only)

False

Returns:

Type Description
Path

Path to the retrieved file/directory in destdir

exists

exists(uri: str) -> bool

Check if local path exists.

list

list(uri: str) -> List[str]

List directory contents, or return single item for file.

put

put(local_path: Path, uri: str) -> str

Copy local file to destination path.

delete

delete(uri: str, recursive: bool = False) -> None

Delete file or directory.

stat

stat(uri: str) -> Dict[str, Any]

Return file metadata.

rompy.transfer.http

HTTP/HTTPS transfer implementation (read-only).

HttpTransfer

Bases: TransferBase

Transfer implementation for http:// and https:// schemes (read-only).

get

get(
    uri: str,
    destdir: Path,
    name: Optional[str] = None,
    link: bool = False,
) -> Path

Download HTTP/HTTPS resource using existing http_handler.

Parameters:

Name Type Description Default
uri str

HTTP/HTTPS URL

required
destdir Path

Destination directory

required
name Optional[str]

Optional name for downloaded file

None
link bool

Ignored for HTTP (always downloads)

False

Returns:

Type Description
Path

Path to downloaded file

exists

exists(uri: str) -> bool

Not supported for HTTP - would require HEAD request.

list

list(uri: str) -> List[str]

Not supported for HTTP - no directory listing.

put

put(local_path: Path, uri: str) -> str

Not supported for HTTP - read-only.

delete

delete(uri: str, recursive: bool = False) -> None

Not supported for HTTP - read-only.

stat

stat(uri: str) -> Dict[str, Any]

Not supported for HTTP - would require HEAD request.

rompy.transfer.cloud

Cloud storage transfer implementation using cloudpathlib.

Supports S3 (s3://), Google Cloud Storage (gs://), and Azure Blob (az://) via cloudpathlib's unified interface.

CloudTransfer

Bases: TransferBase

Transfer implementation for cloud storage via cloudpathlib.

Supports: - S3: s3://bucket/key - Google Cloud Storage: gs://bucket/key - Azure Blob Storage: az://container/blob

Credentials are managed via environment variables: - S3: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION - GCS: GOOGLE_APPLICATION_CREDENTIALS - Azure: AZURE_STORAGE_CONNECTION_STRING

get

get(
    uri: str,
    destdir: Path,
    name: Optional[str] = None,
    link: bool = False,
) -> Path

Download file from cloud storage to local directory.

Parameters:

Name Type Description Default
uri str

Cloud storage URI

required
destdir Path

Local destination directory

required
name Optional[str]

Optional name for downloaded file (default: use cloud object name)

None
link bool

Ignored for cloud storage (always downloads)

False

Returns:

Type Description
Path

Path to downloaded file

Raises:

Type Description
FileNotFoundError

If cloud object does not exist

exists

exists(uri: str) -> bool

Check if cloud object exists.

list

list(uri: str) -> List[str]

List objects under cloud prefix.

Parameters:

Name Type Description Default
uri str

Cloud storage URI (can be directory or file)

required

Returns:

Type Description
List[str]

List of object names (not full URIs)

Raises:

Type Description
FileNotFoundError

If cloud prefix does not exist

put

put(local_path: Path, uri: str) -> str

Upload local file to cloud storage.

Parameters:

Name Type Description Default
local_path Path

Local file path

required
uri str

Cloud destination URI

required

Returns:

Type Description
str

Cloud URI of uploaded object

Raises:

Type Description
FileNotFoundError

If local file does not exist

ValueError

If local_path is a directory (not supported yet)

delete

delete(uri: str, recursive: bool = False) -> None

Delete cloud object.

Parameters:

Name Type Description Default
uri str

Cloud storage URI

required
recursive bool

If True, delete directory recursively

False

Raises:

Type Description
ValueError

If trying to delete directory without recursive=True

stat

stat(uri: str) -> Dict[str, Any]

Get metadata for cloud object.

Parameters:

Name Type Description Default
uri str

Cloud storage URI

required

Returns:

Type Description
Dict[str, Any]

Dictionary with metadata (size, type, etag, etc.)

Raises:

Type Description
FileNotFoundError

If cloud object does not exist

rompy.transfer.oceanum

Oceanum storage transfer implementation using fsspec.

OceanumTransfer

OceanumTransfer()

Bases: TransferBase

Transfer implementation for oceanum:// scheme using fsspec.

Initialize Oceanum transfer with token from environment.

get

get(
    uri: str,
    destdir: Path,
    name: Optional[str] = None,
    link: bool = False,
) -> Path

Download from Oceanum storage to local destdir.

Parameters:

Name Type Description Default
uri str

oceanum:// URI

required
destdir Path

Local destination directory

required
name Optional[str]

Optional name for downloaded file

None
link bool

Ignored for remote storage (always downloads)

False

Returns:

Type Description
Path

Path to downloaded file

exists

exists(uri: str) -> bool

Check if path exists in Oceanum storage.

list

list(uri: str) -> List[str]

List directory contents in Oceanum storage.

put

put(local_path: Path, uri: str) -> str

Upload local file to Oceanum storage.

delete

delete(uri: str, recursive: bool = False) -> None

Delete file/directory from Oceanum storage.

stat

stat(uri: str) -> Dict[str, Any]

Return file metadata from Oceanum storage.

rompy.transfer.utils

parse_scheme

parse_scheme(uri: str) -> str

Return the lower-cased scheme for a URI. - Empty scheme or empty input -> 'file' - Windows drive letters (e.g., 'C:/path') are treated as file scheme - Case-insensitive: returns lowercase - For URIs with a real scheme (e.g., 'https', 's3'), return the scheme

join_prefix

join_prefix(prefix: str, name: str) -> str

Join a destination prefix with a target filename to create a full URI.

Handles various URI schemes (file://, s3://, gs://, http://, etc.) and plain filesystem paths, ensuring proper path construction without double slashes (except in scheme://authority).

Parameters:

Name Type Description Default
prefix str

Destination prefix (folder-like). May be a URI with scheme (e.g., "s3://bucket/outputs/") or plain path ("/local/outputs/").

required
name str

Target filename to append to the prefix (e.g., "output.nc").

required

Returns:

Type Description
str

Complete destination URI or path.

Examples:

>>> join_prefix("s3://bucket/outputs/", "file.nc")
's3://bucket/outputs/file.nc'
>>> join_prefix("s3://bucket/outputs", "file.nc")
's3://bucket/outputs/file.nc'
>>> join_prefix("/local/outputs/", "file.nc")
'/local/outputs/file.nc'
>>> join_prefix("file:///tmp/data/", "file.nc")
'file:///tmp/data/file.nc'
>>> join_prefix("gs://bucket", "file.nc")
'gs://bucket/file.nc'

rompy.transfer.exceptions

UnsupportedOperation

UnsupportedOperation(scheme: str, operation: str)

Bases: Exception

Raised when a transfer implementation doesn't support an operation.

scheme instance-attribute

scheme = scheme

operation instance-attribute

operation = operation