anemoi.utils.remote package
- anemoi.utils.remote.robust(call: callable, *args, maximum_tries: int = 60, retry_after: int = 60, **kwargs) callable
Forwards the arguments to the multiurl robust function. with default retry_after=60 and maximum_tries=60.
- class anemoi.utils.remote.Loader
Bases:
object- transfer_folder(*, source: str, target: str, overwrite: bool = False, resume: bool = False, verbosity: int = 1, threads: int = 1, progress: callable = None) None
Transfer a folder from the source to the target location.
- Parameters:
source (str) – The source folder path.
target (str) – The target folder path.
overwrite (bool, optional) – Whether to overwrite the target if it exists, by default False.
resume (bool, optional) – Whether to resume the transfer if possible, by default False.
verbosity (int, optional) – The verbosity level, by default 1.
threads (int, optional) – The number of threads to use, by default 1.
progress (callable, optional) – A callable for progress reporting, by default None.
- transfer_file(source: str, target: str, overwrite: bool, resume: bool, verbosity: int, threads: int = 1, progress: callable = None, config: dict = None) int
Transfer a file from the source to the target location.
- Parameters:
source (str) – The source file path.
target (str) – The target file path.
overwrite (bool) – Whether to overwrite the target if it exists.
resume (bool) – Whether to resume the transfer if possible.
verbosity (int) – The verbosity level.
threads (int, optional) – The number of threads to use, by default 1.
progress (callable, optional) – A callable for progress reporting, by default None.
config (dict, optional) – Additional configuration options, by default None.
- Returns:
The size of the transferred file.
- Return type:
- Raises:
Exception – If an error occurs during the transfer.
- abstractmethod list_source(source: str) Iterable
List the files in the source location.
- Parameters:
source (str) – The source location.
- Returns:
An iterable of files in the source location.
- Return type:
Iterable
- abstractmethod target_path(source_path: str, source: str, target: str) str
Get the target path for a source file.
- abstractmethod copy(source: str, target: str, **kwargs) None
Copy a file or folder from the source to the target location.
- class anemoi.utils.remote.BaseDownload
Bases:
Loader- action = 'Downloading'
- abstractmethod copy(source: str, target: str, **kwargs) None
Copy a file or folder from the source to the target location.
- get_temporary_target(target: str, pattern: str) str
Get a temporary target path based on the given pattern.
- class anemoi.utils.remote.BaseUpload
Bases:
Loader- action = 'Uploading'
- copy(source: str, target: str, **kwargs) None
Copy a file or folder from the source to the target location.
- list_source(source: str) Iterable
List the files in the source location.
- Parameters:
source (str) – The source location.
- Returns:
An iterable of files in the source location.
- Return type:
Iterable
- exception anemoi.utils.remote.TransferMethodNotImplementedError
Bases:
NotImplementedError
- class anemoi.utils.remote.Transfer(*, source: str, target: str, overwrite: bool = False, resume: bool = False, verbosity: int = 1, threads: int = 1, progress: callable = None, temporary_target: bool = False)
Bases:
objectThis is the internal API and should not be used directly. Use the transfer function instead.
- exception TransferMethodNotImplementedError
Bases:
NotImplementedError
- anemoi.utils.remote.transfer(source, target, *, overwrite=False, resume=False, verbosity=1, progress=None, threads=1, temporary_target=False) Loader
Transfer files or folders from the source to the target location.
- Parameters:
source (str) – A path to a local file or folder or a URL to a file or a folder on S3 or Azure Blob Storage. The url should start with ‘s3://’ or ‘abfs://’, respectively.
target (str) – A path to a local file or folder or a URL to a file or a folder on S3, Azure Blob Storage, or a remote folder. The url should start with ‘s3://’, ‘abfs://’, or ‘ssh://’, respectively.
overwrite (bool, optional) – If the data is already on in the target location it will be overwritten. By default False
resume (bool, optional) – If the data is already on S3 or Azure Blob Storage it will not be uploaded, unless the remote file has a different size. Ignored if the target is an SSH remote folder (ssh://). By default False
verbosity (int, optional) – The level of verbosity, by default 1
progress (callable, optional) – A callable that will be called with the number of files, the total size of the files, the total size transferred and a boolean indicating if the transfer has started. By default None
threads (int, optional) – The number of threads to use when uploading a directory, by default 1
temporary_target (bool, optional) – Experimental feature If True and if the target location supports it, the data will be uploaded to a temporary location then renamed to the final location. Supported by SSH and local targets, not supported by S3 or Azure Blob Storage. By default False.
- Returns:
The Loader instance.
- Return type:
Submodules
anemoi.utils.remote.az module
Management of objects in Azure Blob Storage.
Provides functions to upload, download, list, and delete files and folders, including hierarchical namespace (Azure Data Lake Storage Gen 2).
Only abfs:// scheme URLs are accepted in one of two shapes, including optional query strings for SAS tokens (e.g. suffixed ?sv=…):
abfs://<container>/<path>: account name comes from settings or environment variables
abfs://<container>@<account>.dfs.core.windows.net/<path>?: account name in the URL (.blob.core.windows.net also
accepted)
Credentials can be supplied via ~/.config/anemoi/settings.toml (or settings.secrets.toml) under the object-storage section:
- ```toml
[object-storage] endpoint_url = “…” # for Azure, only needed for sovereign clouds / Azurite account_name = “…” # storage account name account_key = “…” # storage account key sas_token = “?sv=…” # SAS token instead of an account key skip_signature = true # for public / anonymous containers
# container-keyed overrides, if source and destination are in different accounts or have different credentials [“object-storage.training-data”] account_name = “…” sas_token = “?sv=…”
Alternatively, obstore attempts to read standard Azure environment variables directly if no credentials are configured as above. For a list of supported environment variables, see [obstore documentation](https://developmentseed.org/obstore/latest/api/store/azure/#obstore.store.AzureConfig).
- class anemoi.utils.remote.az.AzureObject(url: str)
Bases:
objectParsed representation of an Azure Blob Storage URL.
- anemoi.utils.remote.az.azure_client(obj: str | AzureObject) AzureStore | GCSStore | HTTPStore | S3Store | LocalStore | MemoryStore
Return a cached obstore client for the container referenced by obj.
The client is keyed by account and container so that requests to different accounts sharing a container name do not collide in the cache. Credential precedence, highest to lowest:
SAS token in the URL query
SAS token in settings
Account key in settings
Anonymous access (skip_signature).
If none are set, obstore falls back to the standard AZURE_STORAGE_* environment variables.
- Parameters:
obj (str | AzureObject) – Azure Blob Storage URL or a pre-parsed AzureObject.
- Returns:
Ready-to-use client for the account and container referenced by obj.
- Return type:
obstore.store.ObjectStore
- anemoi.utils.remote.az.list_folder(folder: str) Iterable[ObjectMeta]
List blobs under the URL prefix.
- Parameters:
folder (str) – Azure Blob Storage URL used as a prefix.
- Returns:
One item per blob under the prefix.
- Return type:
Iterable[ObjectMeta]
- anemoi.utils.remote.az.delete_folder(target: str) None
Delete all blobs under the URL prefix.
- Parameters:
target (str) – Azure Blob Storage URL used as a prefix.
- anemoi.utils.remote.az.delete_file(target: str) None
Delete a single blob.
If no blob exists at the URL, a warning is logged and no error is raised.
- Parameters:
target (str) – Azure Blob Storage URL for the blob to delete.
- anemoi.utils.remote.az.delete(target: str) None
Delete a single blob or all blobs under a prefix.
Dispatches to delete_folder if target ends with ‘/’, otherwise delete_file.
- Parameters:
target (str) – Azure Blob Storage URL. Treated as a prefix if it ends with ‘/’, otherwise as a single blob.
- anemoi.utils.remote.az.object_info(target: str | AzureObject) ObjectMeta
Fetch metadata for a single blob.
- Parameters:
target (str | AzureObject) – Azure Blob Storage URL or a pre-parsed AzureObject.
- Returns:
Metadata for the blob, including size, path, and last-modified time.
- Return type:
ObjectMeta
- Raises:
FileNotFoundError – If no blob exists at the URL.
- anemoi.utils.remote.az.object_exists(target: str | AzureObject) bool
Check whether a blob exists at the URL.
- Parameters:
target (str | AzureObject) – Azure Blob Storage URL or a pre-parsed AzureObject.
- Returns:
True if the blob exists, False otherwise.
- Return type:
- anemoi.utils.remote.az.get_object(target: str) Bytes
Fetch a blob and return its contents.
- Parameters:
target (str) – Azure Blob Storage URL.
- Returns:
The blob’s contents.
- Return type:
obstore.Bytes
- anemoi.utils.remote.az.get_objects_parallel(targets: list[str]) list[Bytes]
Fetch multiple blobs concurrently.
Each fetch is retried up to three times on errors other than FileNotFoundError, which is raised immediately without retry.
- Parameters:
- Returns:
Blob contents, in the same order as targets.
- Return type:
list[obstore.Bytes]
- Raises:
FileNotFoundError – If any blob does not exist.
OSError – If any fetch fails three times consecutively for reasons other than the blob being missing.
- anemoi.utils.remote.az.upload(source: str, target: str, *args: bool | int, **kwargs: bool | int) Loader
Upload a local file or directory to Azure Blob Storage via transfer.
- Parameters:
source (str) – Local file or directory path.
target (str) – Azure Blob Storage URL for the destination. Ends with ‘/’ for a directory upload.
*args (bool | int) – Additional positional arguments passed through to transfer.
**kwargs (bool | int) – Additional keyword arguments passed through to transfer.
- Returns:
Loader that performs and reports on the transfer when iterated.
- Return type:
- anemoi.utils.remote.az.upload_file(source: str, target: str, overwrite: bool, resume: bool, verbosity: int) int
Upload a single local file to Azure Blob Storage.
- Parameters:
source (str) – Local file path to upload.
target (str) – Azure Blob Storage URL for the destination blob.
overwrite (bool) – If True, replace any existing blob at the destination.
resume (bool) – If True, skip the upload when a blob of the expected size already exists at the destination.
verbosity (int) – Verbosity level: 0 is silent, higher values show more progress.
- Returns:
Number of bytes transferred.
- Return type:
- Raises:
ValueError – If a blob already exists at the destination and neither overwrite nor resume is set.
- class anemoi.utils.remote.az.AzureUpload
Bases:
BaseUploadTransfer implementation for uploading local files and directories to Azure Blob Storage.
- get_temporary_target(target: str, _: str) str
Return the final target unchanged.
Azure Blob Storage uploads write directly to the destination.
- anemoi.utils.remote.az.download(source: str, target: str, *args: bool | int, **kwargs: bool | int) Loader
Download a blob or prefix from Azure Blob Storage to a local path via transfer.
- Parameters:
- Returns:
Loader that performs and reports on the transfer when iterated.
- Return type:
- anemoi.utils.remote.az.download_file(source: str, target: str, overwrite: bool, resume: bool, verbosity: int) int
Download a single blob to a local file path.
The download is retried up to three times on errors other than FileNotFoundError, which is raised immediately without retry.
- Parameters:
source (str) – Azure Blob Storage URL for the blob to download.
target (str) – Local file path to write.
overwrite (bool) – If True, replace any existing file at the target path.
resume (bool) – If True, skip the download when a file of the expected size already exists at the target.
verbosity (int) – Verbosity level: 0 is silent, higher values show more progress.
- Returns:
Number of bytes transferred.
- Return type:
- Raises:
ValueError – If a file already exists at the target and neither overwrite nor resume is set.
FileNotFoundError – If no blob exists at the source URL.
OSError – If the download fails three times consecutively for reasons other than the blob being missing.
- class anemoi.utils.remote.az.AzureDownload
Bases:
BaseDownloadTransfer implementation for downloading blobs and prefixes from Azure Blob Storage.
- copy(source: str, target: str, **kwargs: Any) None
Copy a single blob or all blobs under a prefix to a local path.
Dispatches to transfer_folder if source ends with ‘/’, otherwise transfer_file.
- list_source(source: str) Iterable[ObjectMeta]
List blobs under the source URL prefix.
- Parameters:
source (str) – Azure Blob Storage URL used as a prefix.
- Yields:
ObjectMeta – One item per blob under the prefix.
- source_path(az_object: ObjectMeta, source: str) str
Build the Azure Blob Storage URL for a single blob within source.
anemoi.utils.remote.s3 module
This module provides functions to upload, download, list and delete files and folders on S3. The functions of this package expect that the AWS credentials are set up in the environment typicaly by setting the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables or by creating a ~/.aws/credentials file. It is also possible to set the endpoint_url in the same file to use a different S3 compatible service:
[default]
endpoint_url = https://some-storage.somewhere.world
aws_access_key_id = xxxxxxxxxxxxxxxxxxxxxxxx
aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxx
Alternatively, the endpoint_url, and keys can be set in one of the ~/.config/anemoi/settings.toml or ~/.config/anemoi/settings.secrets.toml files.
- anemoi.utils.remote.s3.s3_client(obj: str | S3Object) Any
Return a cached S3 client for the given URL.
- anemoi.utils.remote.s3.upload_file(source: str, target: str, overwrite: bool, resume: bool, verbosity: int) int
Upload a file to S3.
- anemoi.utils.remote.s3.download_file(source: str, target: str, overwrite: bool, resume: bool, verbosity: int) int
Download a file from S3.
- anemoi.utils.remote.s3.delete(target: str) None
Delete a file or folder from S3.
- Parameters:
target (str) – S3 URL (file or folder).
- anemoi.utils.remote.s3.list_folder(folder: str) Iterable[dict]
List objects in an S3 folder.
- Parameters:
folder (str) – S3 folder URL.
- Returns:
Iterable of objects.
- Return type:
Iterable
- anemoi.utils.remote.s3.get_object(target: str) bytes
Fetch an S3 object and return its contents as bytes.
- anemoi.utils.remote.s3.get_objects_parallel(targets: list[str]) list[bytes]
Fetch multiple S3 objects concurrently and return their contents.
- anemoi.utils.remote.s3.download(source: str, target: str, *args, **kwargs) None
Download from S3 using transfer utility.
- anemoi.utils.remote.s3.upload(source: str, target: str, *args, **kwargs) None
Upload to S3 using transfer utility.
- class anemoi.utils.remote.s3.S3Upload
Bases:
BaseUpload
- class anemoi.utils.remote.s3.S3Download
Bases:
BaseDownload- list_source(source: str) Iterable[dict]
List objects in S3 source folder.
- Parameters:
source (str) – S3 source folder URL.
- Returns:
Iterable of objects.
- Return type:
Iterable
anemoi.utils.remote.ssh module
- anemoi.utils.remote.ssh.call_process(*args: str) str
Execute a subprocess with the given arguments and return its output.
- Parameters:
args (str) – The command and its arguments to execute.
- Returns:
The standard output of the command.
- Return type:
- Raises:
RuntimeError – If the command returns a non-zero exit code.
- class anemoi.utils.remote.ssh.SshBaseUpload
Bases:
BaseUpload- get_temporary_target(target: str, pattern: str) str
Get a temporary target path based on the given pattern.
- class anemoi.utils.remote.ssh.RsyncUpload
Bases:
SshBaseUpload
- class anemoi.utils.remote.ssh.ScpUpload
Bases:
SshBaseUpload