koladata

Home
Overview
Fundamentals
Glossary
Cheatsheet
API Reference
Quick Recipes
Deep Dive
Common Pitfalls and Gotchas
Persistent Storage

View the Project on GitHub google/koladata

kd.file_io.FileSystemInterface API

Interface to interact with the file system.

FileSystemInterface.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.

FileSystemInterface.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.

FileSystemInterface.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.

FileSystemInterface.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.

FileSystemInterface.exists(self, filepath: str) -> bool

Returns True if the file or directory exists.

FileSystemInterface.glob(self, pattern: str) -> Collection[str]

Returns a list of paths matching a pathname pattern.

FileSystemInterface.is_dir(self, filepath: str) -> bool

Returns True if the path is an existing directory.

FileSystemInterface.make_dirs(self, dirpath: str)

Creates a directory path (and intermediate directories) if not exists.

FileSystemInterface.open(self, filepath: str, mode: str) -> IO[bytes | str]

Opens a file with the given mode.

FileSystemInterface.remove(self, filepath: str)

Removes a file or an empty directory.

FileSystemInterface.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.

FileSystemInterface.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.