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
¶
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 |
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 |
items
class-attribute
instance-attribute
¶
items: list[TransferItemResult] = field(
default_factory=list
)
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 the cached transfer registry.
Lazy-loads the registry on first access.
get_transfer
¶
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
¶
Retrieve data from the given URI and place it under destdir. Returns the final Path to the retrieved object.
exists
abstractmethod
¶
Return True if the given URI exists in the transfer store.
list
abstractmethod
¶
List items under the given URI and return a list of their names/paths.
put
abstractmethod
¶
Upload or copy a local file to the given URI. Returns the URI that was created.
delete
abstractmethod
¶
Delete the resource at the given URI. If recursive is True, delete recursively.
rompy.transfer.file¶
File transfer implementation for local filesystem operations.
FileTransfer
¶
Bases: TransferBase
Transfer implementation for local file:// scheme and plain file paths.
get
¶
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 |
rompy.transfer.http¶
HTTP/HTTPS transfer implementation (read-only).
HttpTransfer
¶
Bases: TransferBase
Transfer implementation for http:// and https:// schemes (read-only).
get
¶
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 |
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
¶
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 |
list
¶
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
¶
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 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 |
rompy.transfer.oceanum¶
Oceanum storage transfer implementation using fsspec.
OceanumTransfer
¶
Bases: TransferBase
Transfer implementation for oceanum:// scheme using fsspec.
Initialize Oceanum transfer with token from environment.
get
¶
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 |
delete
¶
Delete file/directory from Oceanum storage.
rompy.transfer.utils¶
parse_scheme
¶
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 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: