Registry / serialization / libarchive-c

libarchive-c

JSON →
library5.3pypypi✓ verified 83d ago

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-c
INSTALL
IMPORT
SIG · LIBARCHIVE-C
L
libarchive-c
serializationpythonv5.3
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

extract_file
from libarchive import extract_file
import libarchive; libarchive.extract_file(...)

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.

import libarchive import os # Create a dummy file with open('test_file.txt', 'w') as f: f.write('Hello, libarchive-c!') # Create an archive archive_name = 'my_archive.tar' with libarchive.file_writer(archive_name, 'tar') as archive: archive.add_files('test_file.txt') print(f"Archive '{archive_name}' created.") # Clean up the dummy file os.remove('test_file.txt') # Read and extract the archive extracted_dir = 'extracted_content' os.makedirs(extracted_dir, exist_ok=True) os.chdir(extracted_dir) libarchive.extract_file(os.path.join('..', archive_name)) # Extract from parent dir os.chdir('..') # Verify extraction extracted_path = os.path.join(extracted_dir, 'test_file.txt') if os.path.exists(extracted_path): with open(extracted_path, 'r') as f: content = f.read() print(f"Content extracted: {content}") else: print("Extraction failed.") # Clean up archive and extracted directory os.remove(archive_name) os.remove(extracted_path) os.rmdir(extracted_dir)
Debug
Known issues
breakingIf you use the `archive_read_class` or `archive_write_class` arguments for custom archive handling, the classes you provide will now receive a `codec` name as a second positional argument.
fix
Update custom class constructors to accept `codec` argument: `__init__(self, obj, codec)`.
affects: 5.0+
breakingArchive extraction functions now pass `SECURE_NODOTDOT`, `SECURE_NOABSOLUTEPATHS`, and `SECURE_SYMLINKS` flags by default, unless extracting to the root directory. This enhances security but might alter behavior for paths containing '..' or absolute paths within archives, or symbolic links.
fix
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.
affects: 4.0+
breakingThe `ArchiveEntry` properties `atime`, `mtime`, `ctime`, `birthtime`, and `size` now return `None` instead of `0` when the corresponding metadata is unset in the archive.
fix
Update code that checks these properties to explicitly handle `None` values (e.g., `if entry.size is not None: ...`).
affects: 4.0+
breakingThe `ArchiveEntry.pathname` property now attempts to decode bytes using UTF-8 by default, which may break reading archives containing non-UTF-8 filenames that coincidentally resemble UTF-8.
fix
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')`).
affects: 4.0+
breakingSupport for Python 2.7 has been dropped.
fix
Migrate your project to Python 3.
affects: 3.0+
gotchaThe `libarchive-c` Python package is a wrapper around the native `libarchive` C library. This C library must be installed on your system for `libarchive-c` to function.
fix
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.
affects: All versions
gotchaOlder or obsolete versions of the `libarchive` C library (especially those bundled with some operating systems like macOS) may not work correctly or support all features. Python `libarchive-c` is tested against newer versions.
fix
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.
affects: All versions
Upgrade
Version history
5.3latest on PyPI · released May 22, 2025
Audit
Dependencies
libarchive (C library)requiredRequired for `libarchive-c` to function as it's a CFFI binding. Users often need to install this separately via system package managers (e.g., `apt`, `brew`) or by providing its path via the `LIBARCHIVE` environment variable.
Agent activity
23 hits · last 30 days
node
22
Amazon
1
Resources
libarchive-c — pip install libarchive-c · libregistry