File

A File is a Runhouse primitive that represents a file, and can be used to interact with the data at the given path and system.

File Factory Method

runhouse.file(data=None, name: str | None = None, path: str | None = None, system: str | None = None, data_config: Dict | None = None, dryrun: bool = False)[source]

Returns a File object, which can be used to interact with the resource at the given path

Parameters:
  • data – File data. This should be a serializable object.

  • name (Optional[str]) – Name to give the file object, to be reused later on.

  • path (Optional[str]) – Path (or path) of the file object.

  • system (Optional[str or Cluster]) – File system or cluster name. If providing a file system this must be one of: [file, github, sftp, ssh, s3, gs, azure]. We are working to add additional file system support.

  • data_config (Optional[Dict]) – The data config to pass to the underlying fsspec handler.

  • dryrun (bool) – Whether to create the File if it doesn’t exist, or load a File object as a dryrun. (Default: False)

Returns:

The resulting file.

Return type:

File

Example

File Class

class runhouse.File(path: str | None = None, name: str | None = None, system: str | None = 'file', env: Env | None = None, data_config: Dict | None = None, dryrun: bool = False, **kwargs)[source]
__init__(path: str | None = None, name: str | None = None, system: str | None = 'file', env: Env | None = None, data_config: Dict | None = None, dryrun: bool = False, **kwargs)[source]

Runhouse File object

Note

To build a File, please use the factory method file().

exists_in_system()[source]

Check whether the file exists in the file system

Example

open(mode: str = 'rb')[source]

Get a file-like (OpenFile container object) of the file data. User must close the file, or use this method inside of a with statement.

Example

resolved_state(deserialize: bool = True, mode: str = 'rb')[source]

Return the data for the user to deserialize. Primarily used to define the behavior of the fetch method.

Example

rm()[source]

Delete the file and the folder it lives in from the file system.

Example

to(system, env: str | Env | None = None, path: str | None = None, data_config: dict | None = None)[source]

Return a copy of the file on the destination system and path.

Example

write(data, serialize: bool = True, mode: str = 'wb')[source]

Save the underlying file to its specified fsspec URL.

Example