libarchive-c is a Python interface to the C library libarchive, allowing users to read, write, and extract various archive formats like tar, zip, and 7z. It leverages `ctypes` for dynamic loading and is actively maintained, with regular releases (e.g., v5.3 released May 22, 2025). It is currently tested with Python 3.12 and 3.13.
pip install libarchive-cVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create a simple 'tar' archive with a file, and then extract its contents using the high-level `file_writer` and `extract_file` functions.
Update custom class constructors to accept `codec` argument: `__init__(self, obj, codec)`.
Review extraction logic, especially when dealing with potentially malicious archives or specific path structures. Explicitly pass desired `flags` to extraction functions if default behavior is not suitable.
Update code that checks these properties to explicitly handle `None` values (e.g., `if entry.size is not None: ...`).
When reading archives with non-UTF-8 metadata, specify the correct `header_codec` argument to `file_reader` (e.g., `libarchive.file_reader('archive.zip', header_codec='cp437')`).Migrate your project to Python 3.
Install `libarchive` via your system's package manager (e.g., `sudo apt-get install libarchive-dev` on Debian/Ubuntu, `brew install libarchive` on macOS). On Windows, you may need to download the `libarchive.dll` and its dependencies and ensure it's in your system PATH or specified via the `LIBARCHIVE` environment variable.
Ensure you have a recent version of the `libarchive` C library installed. If issues persist, consider installing a newer version via `brew` (macOS) or compiling from source, and point `libarchive-c` to it using the `LIBARCHIVE` environment variable.