packio.io ========= .. py:module:: packio.io .. autoapi-nested-parse:: Tools to read and write multiple data objects using a single file path. Classes ------- .. autoapisummary:: packio.io.ArchiveWriter packio.io.Writer packio.io.Reader Module Contents --------------- .. py:class:: ArchiveWriter Manage addition of files to zipfile archive. :param tempdir: Temporary directory to write files to. :param writer: Callable to copy files from tempdir into the archive. :param filenames: List of filenames to add to the archive. .. py:attribute:: tempdir :type: pathlib.Path .. py:attribute:: writer :type: Callable[[str, Any], None] .. py:attribute:: filenames :type: set[str] .. py:method:: __post_init__() -> None Validate inputs. .. py:method:: file(filename: str) -> pathlib.Path Declare a file name to add to the archive, and return a temp path to write to. .. py:method:: zip_files(**kwargs: Any) -> None Write all files to the zip archive. :param \*\*kwargs: Additional keyword arguments to pass in to zipfile.ZipFile.write. .. py:class:: Writer(path: pathlib.Path) Context manager to write multiple objects to the same file. Initialize the reader with a file path. .. py:attribute:: path .. py:method:: __enter__() -> ArchiveWriter Create temporary directory and zip object, return callable. .. py:method:: __exit__(exc_type: Type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None) -> None Exit the context manager. .. py:class:: Reader(path: pathlib.Path) Context manager to read multiple objects from the same file. Initialize zipfile with a file path. .. py:attribute:: path .. py:method:: __enter__() -> Reader Create temporary directory and zip object, return callable. .. py:method:: file(filename: str) -> pathlib.Path Unzip the file to a temporary path and return that path. .. py:method:: __exit__(exc_type: Type[BaseException] | None, exc_value: BaseException | None, traceback: types.TracebackType | None) -> None Exit the context manager.