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, provenance=None, access_level: ResourceAccess | None = ResourceAccess.WRITE, visibility: ResourceVisibility | None = ResourceVisibility.PRIVATE, **kwargs)[source]#
__init__(name: str | None = None, dryrun: bool = False, provenance=None, access_level: ResourceAccess | None = ResourceAccess.WRITE, visibility: ResourceVisibility | None = ResourceVisibility.PRIVATE, **kwargs)[source]#

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

Runhouse currently supports the following builtin Resource types:

delete_configs()[source]#

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

classmethod from_name(name, dryrun=False, alt_options=None)[source]#

Load existing Resource via its name.

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

Return the history of the resource, including specific config fields (e.g. blob path) and which runs have overwritten it. If limit is specified, return the last limit number of entries in the history.

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.

  • 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.

Maybe later, account for folders along the path with a different RNS name.

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). If a user has a Runhouse account they will receive an email notifying them of their new access. If the user does not have a Runhouse account they will also receive instructions on creating one, after which they will be able to have access to 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.

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

  • visibility (ResourceVisibility, optional) – Type of visibility to provide for the shared resource. Defaults to private.

  • 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. Defaults to 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", "[email protected]"], 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.