modal.NetworkFileSystem

A shared, writable file system accessible by one or more Modal functions.

By attaching this file system as a mount to one or more functions, they can share and persist data with each other.

Note: NetworkFileSystem has been deprecated and will be removed.

Usage

Also see the CLI methods for accessing network file systems:

A NetworkFileSystem can also be useful for some local scripting scenarios, e.g.:

hydrate 

Synchronize the local object with its identity on the Modal server.

It is rarely necessary to call this method explicitly, as most operations will lazily hydrate when needed. The main use case is when you need to access object metadata, such as its ID.

Added in v0.72.39: This method replaces the deprecated .resolve() method.

from_name 

Reference a NetworkFileSystem by its name, creating if necessary.

This is a lazy method that defers hydrating the local object with metadata from Modal servers until the first time it is actually used.

ephemeral 

Creates a new ephemeral network filesystem within a context manager:

Usage:

delete 

write_file 

Write from a file object to a path on the network file system, atomically.

Will create any needed parent directories automatically.

If remote_path ends with / it’s assumed to be a directory and the file will be uploaded with its current name to that directory.

read_file 

Read a file from the network file system

iterdir 

Iterate over all files in a directory in the network file system.

  • Passing a directory path lists all files in the directory (names are relative to the directory)
  • Passing a file path returns a list containing only that file’s listing description
  • Passing a glob path (including at least one * or ** sequence) returns all files matching that glob path (using absolute paths)

add_local_file 

add_local_dir 

listdir 

List all files in a directory in the network file system.

  • Passing a directory path lists all files in the directory (names are relative to the directory)
  • Passing a file path returns a list containing only that file’s listing description
  • Passing a glob path (including at least one * or ** sequence) returns all files matching that glob path (using absolute paths)

remove_file 

Remove a file in a network file system.