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. The url should start with ‘s3://’.
target (str) – A path to a local file or folder or a URL to a file or a folder on S3 or a remote folder. The url should start with ‘s3://’ or ‘ssh://’.
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 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. By default False.
- Returns:
The Loader instance.
- Return type:
Submodules
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