Image

Image Class

class runhouse.Image(name: str, image_id: str | None = None)[source]
__init__(name: str, image_id: str | None = None)[source]

Runhouse Image object, specifying cluster setup properties and steps.

Parameters:
  • name (str) – Name to assign the Runhouse image.

  • image_id (str) – Machine image to use, if any. (Default: None)

Example

>>> my_image = ( >>> rh.Image(name="base_image") >>> .setup_conda_env( >>> conda_env_name="base_env", >>> conda_config={"dependencies": ["python=3.11"], "name": "base_env"}, >>> ) >>> .install_packages(["numpy", "pandas"]) >>> .set_env_vars({"OMP_NUM_THREADS": 1}) >>> )
from_docker(image_id: str, docker_secret: Secret | str = None)[source]

Set up and use an existing Docker image.

Parameters:
  • image_id (str) – Docker image in the following format “<registry>/<image>:<tag>”

  • docker_secret (Secret or str, optional) – Runhouse secret corresponding to information necessary to pull the image from a private registry, such as Docker Hub or cloud provider. See DockerRegistrySecret for more information.

install_packages(reqs: List[Package | str], conda_env_name: str | None = None)[source]

Install the given packages.

Parameters:
  • reqs (List[Package or str]) – List of packages to install on cluster and env.

  • node (str, optional) – Cluster node to install the package on. If specified, will use ssh to install the package. (Default: None)

  • conda_env_name (str, optional) – Name of conda env to install the package in, if relevant. If left empty, defaults to base environment. (Default: None)

rsync(source: str, dest: str, contents: bool = False, filter_options: str | None = None)[source]

Sync the contents of the source directory into the destination.

Parameters:
  • source (str) – The source path.

  • dest (str) – The target path.

  • contents (Optional[bool], optional) – Whether the contents of the source directory or the directory itself should be copied to destination. If True the contents of the source directory are copied to the destination, and the source directory itself is not created at the destination. If False the source directory along with its contents are copied ot the destination, creating an additional directory layer at the destination. (Default: False).

  • filter_options (Optional[str], optional) – The filter options for rsync.

run_bash(command: str, conda_env_name: str | None = None)[source]

Run bash commands.

Parameters:
  • command (str) – Commands to run on the cluster.

  • conda_env_name (str or None) – Name of conda env to run the command in, if applicable. (Defaut: None)

set_env_vars(env_vars: str | Dict)[source]

Set environment variables.

Parameters:

env_vars (str or Dict) – Dict of environment variables and values to set, or string pointing to local .env file consisting of env vars to set.

setup_conda_env(conda_env_name: str, conda_config: str | Dict)[source]

Setup Conda env

Parameters:
  • conda_env_name (str) – Name of conda env to create.

  • conda_config (str or Dict) – Path or Dict referring to the conda yaml config to use to create the conda env.

sync_secrets(providers: List[str | Secret])[source]

Send secrets for the given providers.

Parameters:

providers (List[str or Secret]) – List of providers to send secrets for.

ImageSteupStepType

class runhouse.resources.images.ImageSetupStepType(value)[source]

Enum for valid Image setup step types

PACKAGES = 'packages'
CMD_RUN = 'cmd_run'
SETUP_CONDA_ENV = 'setup_conda_env'
RSYNC = 'rsync'
SYNC_SECRETS = 'sync_secrets'
SET_ENV_VARS = 'set_env_vars'

ImageSetupStep

class runhouse.resources.images.ImageSetupStep(step_type: ImageSetupStepType, **kwargs: Dict[str, Any])[source]
__init__(step_type: ImageSetupStepType, **kwargs: Dict[str, Any])[source]

A component of the Runhouse Image, consisting of the step type (e.g. packages, set_env_vars), along with arguments to provide to the function corresponding to the step type.

Parameters:
  • step_type (ImageSetupStepType) – Type of setup step used to provide the Image.

  • kwargs (Dict[str, Any]) – Please refer to the corresponding functions in Image to determine the correct keyword arguments to provide.