NetworkFileSystem provides 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.
Basic usage
Creating a NetworkFileSystem
Reference by name
Ephemeral NetworkFileSystem
Create a temporary NetworkFileSystem that exists only within a context manager:Managing files
Write files
Write from a file object to a path on the network file system:/, it’s treated as a directory and the file is uploaded with its current name:
Read files
Read a file from the network file system:Add local files
Upload a local file to the network file system:remote_path is not specified, the file is uploaded to the root with its current name:
Add local directories
Upload an entire local directory:List files
List all files in a directory:Remove files
Remove a file or directory:Local scripting
ANetworkFileSystem can be useful for local scripting scenarios:
CLI access
You can also manage network file systems using the Modal CLI:Managing NetworkFileSystems
Delete a NetworkFileSystem
API reference
NetworkFileSystem methods
Write from a file object to a path, atomically. Will create any needed parent directories.Parameters:
remote_path(str): Path on the network file systemfp(BinaryIO): File object to read fromprogress_cb(callable, optional): Progress callback function
Read a file from the network file system. Yields bytes chunks.Parameters:
path(str): Path to the file
Upload a local file to the network file system.Parameters:
local_path(str | Path): Local file pathremote_path(str | PurePosixPath, optional): Remote path. Defaults to root with file’s current nameprogress_cb(callable, optional): Progress callback function
Upload a local directory to the network file system.Parameters:
local_path(str | Path): Local directory pathremote_path(str | PurePosixPath, optional): Remote path. Defaults to root with directory’s current nameprogress_cb(callable, optional): Progress callback function
List all files in a directory. Returns a list of
FileEntry objects.Parameters:path(str): Directory path, file path, or glob pattern
Iterate over all files in a directory. Yields
FileEntry objects.Parameters:path(str): Directory path, file path, or glob pattern
Remove a file or directory.Parameters:
path(str): Path to removerecursive(bool): If True, remove directories recursively. Default: False
FileEntry
TheFileEntry dataclass represents a file or directory entry:
path(str): File pathtype(FileEntryType): FILE, DIRECTORY, SYMLINK, FIFO, or SOCKETmtime(int): Modification timesize(int): File size in bytes