You are viewing main version. Click here to see docs for the latest stable version.

Resource

Resources are the Runhouse abstraction for objects that can be saved, shared, and reused.

Resource Class

class runhouse.resources.resource.Resource(name: str | None = None, dryrun: bool = False, access_level: ResourceAccess = ResourceAccess.WRITE, visibility: ResourceVisibility = ResourceVisibility.PRIVATE, **kwargs)[source]
__init__(name: str | None = None, dryrun: bool = False, access_level: ResourceAccess = ResourceAccess.WRITE, visibility: ResourceVisibility = ResourceVisibility.PRIVATE, **kwargs)[source]

Runhouse abstraction for objects that can be saved, shared, and reused.

Parameters:
  • name (Optional[str], optional) – Name to assign the resource. (Default: None)

  • dryrun (bool, optional) – Whether to create the resource object, or load the object as a dryrun. (Default: False)

  • access_level (ResourceAccess, optional) – Access level to provide for the resource. (Default: ResourceAccess.WRITE)

  • visibility (ResourceVisibility, optional) – Type of visibility to provide for the resource. (Default: ResourceVisibility.PRIVATE)

delete_configs()[source]

Delete the resource’s config from local working_dir and RNS config store.

static from_config(config: Dict, dryrun: bool = False, _resolve_children: bool = True)[source]

Load or construct resource from config.

Parameters:
  • config (Dict) – Resource config.

  • dryrun (bool, optional) – Whether to construct resource or load as dryrun (Default: False)

classmethod from_name(name: str, load_from_den: bool = True, dryrun: bool = False, _alt_options: Dict | None = None, _resolve_children: bool = True)[source]

Load existing Resource via its name.

Parameters:
  • name (str) – Name of the resource to load from name.

  • load_from_den (bool, optional) – Whether to try loading the module from Den. (Default: True)

  • dryrun (bool, optional) – Whether to construct the object or load as dryrun. (Default: False)

history(limit: int | None = None) List[Dict][source]

Return the history of the resource, including specific config fields (e.g. folder path) and which runs have overwritten it.

Parameters:

limit (int, optional) – If specified, return the last limit number of entries in the history. Otherwise, return the entire history. (Default: None)

pin()[source]

Write the resource to the object store.

refresh()[source]

Update the resource in the object store.

revoke(users: str | List[str] | None = None, headers: Dict | None = None)[source]

Revoke access to the resource.

Parameters:
  • users (Union[str, str], optional) – List of user emails and / or runhouse account usernames (or a single user). If no users are specified will revoke access for all users. (Default: None)

  • headers (Optional[Dict]) – Request headers to provide for the request to RNS. Contains the user’s auth token. Example: {"Authorization": f"Bearer {token}"}

property rns_address

Traverse up the filesystem until reaching one of the directories in rns_base_folders, then compute the relative path to that.

save(name: str | None = None, overwrite: bool = True, folder: str | None = None)[source]

Register the resource, saving it to local working_dir config and RNS config store. Uses the resource’s self.config() to generate the dict to save.

save_attrs_to_config(config: Dict, attrs: List[str])[source]

Save the given attributes to the config

share(users: str | List[str] | None = None, access_level: ResourceAccess | str = ResourceAccess.READ, visibility: ResourceVisibility | str | None = None, notify_users: bool = True, headers: Dict | None = None) Tuple[Dict[str, ResourceAccess], Dict[str, ResourceAccess]][source]

Grant access to the resource for a list of users (or a single user). By default, the user will receive an email notification of access (if they have a Runhouse account) or instructions on creating an account to access the resource. If visibility is set to public, users will not be notified.

Note

You can only grant access to other users if you have write access to the resource.

Parameters:
  • users (Union[str, list], optional) – Single user or list of user emails and / or runhouse account usernames. If none are provided and visibility is set to public, resource will be made publicly available to all users. (Default: None)

  • access_level (ResourceAccess, optional) – Access level to provide for the resource. (Default: read).

  • visibility (ResourceVisibility, optional) – Type of visibility to provide for the shared resource. By default, the visibility is private. (Default: None)

  • notify_users (bool, optional) – Whether to send an email notification to users who have been given access. Note: This is relevant for resources which are not shareable. (Default: True)

  • headers (Dict, optional) – Request headers to provide for the request to RNS. Contains the user’s auth token. Example: {"Authorization": f"Bearer {token}"}

Returns:

added_users:

Users who already have a Runhouse account and have been granted access to the resource.

new_users:

Users who do not have Runhouse accounts and received notifications via their emails.

valid_users:

Set of valid usernames and emails from users parameter.

Return type:

Tuple(Dict, Dict, Set)

Example

>>> # Write access to the resource for these specific users. >>> # Visibility will be set to private (users can search for and view resource in Den dashboard) >>> my_resource.share(users=["username1", "user2@gmail.com"], access_level='write')
>>> # Make resource public, with read access to the resource for all users >>> my_resource.share(visibility='public')
unname()[source]

Remove the name of the resource. This changes the resource name to anonymous and deletes any local or RNS configs for the resource.