Skip to main content
The Latch SDK provides a convenient means of referencing files or directories hosted on Latch within task functions.

Downloading Files

To download files locally:
To download files to a pre-determined local path:

Caching File Downloads

By default, the download method will not cache the file. To enable caching, pass cache=True.
If you do not provide a local destination path, the file will be downloaded to the default ~/.latch/ directory. Without caching enabled, this can result in multiple downloads of the same file, unnecessarily increasing storage usage. To avoid this, it is strongly recommended to set a destination path and enable caching, especially when using LPath in Latch Pods or Latch Plots.

Uploading Files

To upload files from a local path to a Latch path:
To upload to a remote path, the parent directory of the remote path must already exist. To ensure that the parent directory exists, use LPath("latch:///parent_directory").mkdirp().

Copying Between Latch Paths

Copy data from one Latch path to another:

Deleting Latch Files

Recursively remove a remote file or directory:

Fetching File Metadata

Use the following methods to fetch metadata of your remote files without downloading the file first:
  1. node_id()
  2. name()
  3. content_type()
  4. size()
LPath objects will cache metadata information for the lifetime of the object after any LPath method is invoked. To re-populate the cache, use the LPath().fetch_metadata() method. For example:

Working with Directories

LPath also provides the methods for working with remote directories. For example:
The size_recursive method can be very slow on large directories and should only be used if absolutely necessary.