A module for extracting archive files, which wraps the patoolib library, can recursively process nested compressed package files.
Project description
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. - Source cleanup: Delete source archives only after successful extraction when
cleanup=True. - Backend options: Pass
program,interactive,password, andverbositytopatool.
[!IMPORTANT] Supported archive formats depend on
patooland the archive programs installed on your system. Install the required backend programs before processing formats such as7zorrar.
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 |
[!NOTE]
extract()andextractall()returnNonewhen validation or extraction fails. Passing amodeother than"x"or"e"raisesValueError.
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}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file archextractor-0.2.2.tar.gz.
File metadata
- Download URL: archextractor-0.2.2.tar.gz
- Upload date:
- Size: 34.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
180be964bd98f678fa4a91a3aa9e20b1228559d898adce51abc45d75a0bc66bf
|
|
| MD5 |
22d832b0e456463c89745edb64dd5eab
|
|
| BLAKE2b-256 |
2017bf99a8e534e87f514967c0229c59a7fdbdce69054363e2ddf6c47df67b71
|
Provenance
The following attestation bundles were made for archextractor-0.2.2.tar.gz:
Publisher:
python-publish.yml on 2513502304/ArchExtractor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
archextractor-0.2.2.tar.gz -
Subject digest:
180be964bd98f678fa4a91a3aa9e20b1228559d898adce51abc45d75a0bc66bf - Sigstore transparency entry: 2066560526
- Sigstore integration time:
-
Permalink:
2513502304/ArchExtractor@c6a712f122712d6a106843b59196aa583fed6c80 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/2513502304
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c6a712f122712d6a106843b59196aa583fed6c80 -
Trigger Event:
release
-
Statement type:
File details
Details for the file archextractor-0.2.2-py3-none-any.whl.
File metadata
- Download URL: archextractor-0.2.2-py3-none-any.whl
- Upload date:
- Size: 29.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d549ce814b17fb0c6875e6461509d2ff93b30287e28386ce58b3851bee5a96f8
|
|
| MD5 |
23351a8dd23f0b9cb2bfd7ab4d447458
|
|
| BLAKE2b-256 |
76824ac0af9b7d35a689fca7a2078c231847d40997c82dc314013d1a7f112bee
|
Provenance
The following attestation bundles were made for archextractor-0.2.2-py3-none-any.whl:
Publisher:
python-publish.yml on 2513502304/ArchExtractor
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
archextractor-0.2.2-py3-none-any.whl -
Subject digest:
d549ce814b17fb0c6875e6461509d2ff93b30287e28386ce58b3851bee5a96f8 - Sigstore transparency entry: 2066560532
- Sigstore integration time:
-
Permalink:
2513502304/ArchExtractor@c6a712f122712d6a106843b59196aa583fed6c80 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/2513502304
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c6a712f122712d6a106843b59196aa583fed6c80 -
Trigger Event:
release
-
Statement type: