packio documentation

Public methods and classes for packio package.

class packio.Reader(path: Path)

Bases: object

Context manager to read multiple objects from the same file.

file(filename: str) Path

Unzip the file to a temporary path and return that path.

class packio.Writer(path: Path)

Bases: object

Context manager to write multiple objects to the same file.

packio.unzipflat(*, file: str | Path, dest_dir: str | Path, overwrite: bool = False) None

Unzip a file into a destination directory.

Parameters:
  • file – Path to the zip archive.

  • dest_dir – An existing directory to unzip the archive into.

  • overwrite – If True, overwrite any existing files in the destination directory.

Raises:
  • ValueError – If the input file is not a zip archive.

  • ValueError – If any contents of the input zip archive are directories – expect a flat archive.

  • FileExistsError – If any files in the archive would overwrite existing files in the destination directory.

packio.zipflat(*, files: list[str | Path], outfile: str | Path) None

Zip files into a single archive with no directory structure.

Parameters:
  • files – List of files to zip.

  • outfile – Path to the resulting zip archive.

Raises:

ValueError – If the names of the provided files are not unique.