Skip to content

hyperion.adapters.keyval.filesystem

hyperion.adapters.keyval.filesystem

Filesystem-backed :class:KeyValueStore adapter (lite -- stdlib only).

One file per (hashed, prefixed) key under a root directory, mirroring the LocalFileCache idiom. Keys are url-safe-base64 encoded into filenames so arbitrary keys (containing /, : ...) are safe and reversible. Writes are atomic and durable (write to a temp file in the same directory, fsync, then os.replace; the temp file is removed if the write fails).

FilesystemStore

FilesystemStore(root_path, prefix=None, compression=None)

Bases: KeyValueStore

A persistent key-value store backed by a directory of files.

Source code in hyperion/adapters/keyval/filesystem.py
def __init__(
    self,
    root_path: Path | str,
    prefix: str | None = None,
    compression: CompressionType | None = None,
) -> None:
    super().__init__(prefix, compression)
    self.root_path = Path(root_path)
    if self.root_path.exists() and not self.root_path.is_dir():
        raise ValueError(f"Given key-value store path ({self.root_path.as_posix()}) is not a directory.")
    self.root_path.mkdir(parents=True, exist_ok=True)
    logger.info("Initialized FilesystemStore.", root_path=self.root_path.as_posix())