Home
Overview
Fundamentals
Glossary
Cheatsheet
API Reference
Quick Recipes
Deep Dive
Common Pitfalls and Gotchas
Persistent Storage
Interacts with the file system.
FileSystemInteraction.bulk_make_dirs(self, dirpaths: Collection[str])Creates multiple directory paths (and intermediate directories).
Raises an exception on error; it is not specified whether some operations
may be partially completed.
Args:
dirpaths: Collection of directory paths to create.
FileSystemInteraction.bulk_remove(self, filepaths: Collection[str])Removes multiple files or directories.
Raises an exception on error; it is not specified whether some operations
may be partially completed.
Args:
filepaths: Collection of file or directory paths to remove.
FileSystemInteraction.bulk_stat(self, filepaths: Collection[str]) -> dict[str, StatResult]Returns metadata for multiple files or directories.
Raises an exception on error, for example if at least one file or directory
does not exist.
Args:
filepaths: Collection of file or directory paths to inspect.
FileSystemInteraction.bulk_write(self, files: Mapping[str, bytes])Writes multiple files with their respective byte contents.
Raises an exception on error; it is not specified whether some operations
may be partially completed.
Args:
files: Mapping from file paths to their byte contents.
FileSystemInteraction.exists(self, filepath: str) -> boolReturns True if the file or directory exists.
FileSystemInteraction.glob(self, pattern: str) -> Collection[str]Returns a list of paths matching a pathname pattern.
FileSystemInteraction.is_dir(self, filepath: str) -> boolReturns True if the path is an existing directory.
FileSystemInteraction.make_dirs(self, dirpath: str)Creates a directory path (and intermediate directories) if not exists.
FileSystemInteraction.open(self, filepath: str, mode: str) -> IO[bytes | str]Opens a file with the given mode.
FileSystemInteraction.remove(self, filepath: str)Removes a file or an empty directory.
FileSystemInteraction.rename(self, oldpath: str, newpath: str, overwrite: bool = False)Rename or move a file or a directory.
Atomicity should be an aspirational goal for implementations, especially for
file-to-file renaming. It is unfortunately not an API guarantee at present.
Args:
oldpath: the file or directory to be moved.
newpath: the new name of the file or directory.
overwrite: boolean; if False, it is an error for newpath to be occupied by
an existing file or directory.
FileSystemInteraction.walk(self, top: str) -> Iterator[tuple[str, list[str], list[str]]]Directory tree generator yielding (dirpath, dirnames, filenames).
Can be called on non-existing directories, in which case the returned
generator is empty.
Args:
top: Root directory path to walk.