ArchExtractor
A Python module for extracting archive files, with support for recursively unpacking nested archives.
ArchExtractor wraps patool with a small, reusable API for archive validation, single archive extraction, recursive extraction, output flattening, and cleanup of common system/tool-generated files.
Feature
- Archive test: Validate whether a file is a processable archive before extraction.
- Extract one: Extract a single archive without processing nested archives.
- Extract all: Recursively extract nested archive files found in the output directory.
- Output mode: Preserve the original directory tree with
mode="x"or flatten files into the destination directory withmode="e"; duplicate flattened file names are renamed with suffixes such as(1)to avoid overwrites. - Generated file cleanup: Remove common system/tool-generated files such as
__MACOSX,.DS_Store,PaxHeader, andThumbs.db. A directory is removed only when it matches a directory pattern (__MACOSX,.Trashes,PaxHeader, ...); file patterns such as editor backups (*~) orIconnever remove a folder that merely shares the name. - Safe destination: Each extraction runs in a private staging directory inside
dst, so cleanup and flattening only touch the files that call produced. Existing content ofdstis never deleted, moved, or overwritten (a name clash is renamed with a suffix such as(1)), and a failed extraction leaves nothing behind indst. - Source cleanup: Delete source archives only after successful extraction when
cleanup=True. - Backend options: Pass
program,interactive,password, andverbositytopatool.
QuickStart
Install the Python package:
# pip
python3 -m pip install archextractor
# uv
uv add archextractor
Install common archive backends:
# Ubuntu / Debian
sudo apt-get install p7zip-full unrar
# macOS
brew install 7zip rar
API
| Method | Description | Return |
|---|---|---|
test_archive(src, ...) |
Test whether src is a readable archive supported by patool. |
bool |
extract(src, dst, ...) |
Extract one archive without recursively processing nested archives. | str | None |
extractall(src, dst, ...) |
Extract one archive and recursively extract nested archives found under dst. |
str | None |
Usage
from archextractor import ArchExtractor
# Initialize one reusable extractor
extractor = ArchExtractor()
# Test whether ``src`` is a readable archive supported by patool
is_valid = extractor.test_archive(
src="/data/archive.tar", # The source path of the archive file (only file path, not directory path)
verbosity=-1, # Larger values print more information. 0 is the default, -1 or lower means no output, values >= 1 prints command output
program=None, # Select a specific archive program, or let patool search for a suitable program in PATH
interactive=False, # If True, wait for user input when the backend program asks for it
password=None, # Password for encrypted archives, passed to the backend program when supported
)
print(is_valid)
# Extract a single archive without recursively processing nested archives
result = extractor.extract(
src="/data/archive.tar", # The source path of the archive file (only file path, not directory path)
dst="/data/unpacked", # The destination path of the extracted files (only directory path, not file path)
mode="x", # "x" preserves the original directory structure; "e" flattens files and renames duplicate file names with suffixes such as "(1)" to avoid overwrites
verbosity=-1, # Larger values print more information. 0 is the default, -1 or lower means no output, values >= 1 prints command output
program=None, # Select a specific archive program, or let patool search for a suitable program in PATH
interactive=False, # If True, wait for user input when the backend program asks for it
password=None, # Password for encrypted archives, passed to the backend program when supported
cleanup=False, # Delete the source archive file after successful extraction
)
if result is None:
print("Extraction failed")
else:
print(f"Extracted to: {result}")
# Extract ``src`` and recursively extract nested archives found under ``dst``
result = extractor.extractall(
src="/data/archive.tar", # The source path of the archive file (only file path, not directory path)
dst="/data/unpacked", # The destination path of the extracted files (only directory path, not file path)
mode="e", # "e" flattens extracted files and renames duplicate file names with suffixes such as "(1)" to avoid overwrites; "x" preserves the original directory structure
verbosity=-1, # Larger values print more information. 0 is the default, -1 or lower means no output, values >= 1 prints command output
program=None, # Select a specific archive program, or let patool search for a suitable program in PATH
interactive=False, # If True, wait for user input when the backend program asks for it
password=None, # Password for encrypted archives, passed to the backend program when supported
cleanup=True, # Delete source archive files after successful extraction
)
if result is None:
print("Extraction failed")
else:
print(f"Extracted to: {result}")
Metadata
Release files for archextractor 0.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| archextractor-0.2.3.tar.gz | 38.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| archextractor-0.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 70.0 kB
Release files / archextractor-0.2.3.tar.gz
| Download URL | archextractor-0.2.3.tar.gz |
|---|---|
| Size | 38.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4a831e7aee3c570aa19963ba078b9166e1604869a5a28638047363cd8c57d2ab
|
|
BLAKE2b-256 checksum How to use checksums |
cab643033b5658cd0e81a961fbd164adeeb4eeee369546dc0d405fa27bba4988
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency logRelease files / archextractor-0.2.3-py3-none-any.whl
| Download URL | archextractor-0.2.3-py3-none-any.whl |
|---|---|
| Size | 31.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8fe831f39008dd8f61306c17477f3cd2b705a123938dd91ee6ebcb6c25f37790
|
|
BLAKE2b-256 checksum How to use checksums |
a37750636439e3389f86927db163e5f38be1d637375d07aacfc5e7ee42d97ca0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 16, 2026.
Transparency log