packio.io

Tools to read and write multiple data objects using a single file path.

Classes

ArchiveWriter

Manage addition of files to zipfile archive.

Writer

Context manager to write multiple objects to the same file.

Reader

Context manager to read multiple objects from the same file.

Module Contents

class packio.io.ArchiveWriter[source]

Manage addition of files to zipfile archive.

Parameters:
  • tempdir – Temporary directory to write files to.

  • writer – Callable to copy files from tempdir into the archive.

  • filenames – List of filenames to add to the archive.

tempdir: pathlib.Path[source]
writer: Callable[[str, Any], None][source]
filenames: set[str][source]
__post_init__() None[source]

Validate inputs.

file(filename: str) pathlib.Path[source]

Declare a file name to add to the archive, and return a temp path to write to.

zip_files(**kwargs: Any) None[source]

Write all files to the zip archive.

Parameters:

**kwargs – Additional keyword arguments to pass in to zipfile.ZipFile.write.

class packio.io.Writer(path: pathlib.Path)[source]

Context manager to write multiple objects to the same file.

Initialize the reader with a file path.

path[source]
__enter__() ArchiveWriter[source]

Create temporary directory and zip object, return callable.

__exit__(exc_type: Type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None) None[source]

Exit the context manager.

class packio.io.Reader(path: pathlib.Path)[source]

Context manager to read multiple objects from the same file.

Initialize zipfile with a file path.

path[source]
__enter__() Reader[source]

Create temporary directory and zip object, return callable.

file(filename: str) pathlib.Path[source]

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

__exit__(exc_type: Type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None) None[source]

Exit the context manager.