unpack archive files in Python
Links:
Features:
- unpack archive files without password
- very simple interface
- command line interface and library
- supported python versions: 3.7, 3.8, 3.9, 3.10
- tested platforms: Linux, macOS, Windows
- back-ends:
- zipfile: included in Python
- patool: It relies on helper applications to handle those archive formats (for example bzip2 for BZIP2 archives). Supported formats: 7z (.7z), ACE (.ace), ALZIP (.alz), AR (.a), ARC (.arc), ARJ (.arj), BZIP2 (.bz2), CAB (.cab), compress (.Z), CPIO (.cpio), DEB (.deb), DMS (.dms), GZIP (.gz), LRZIP (.lrz), LZH (.lha, .lzh), LZIP (.lz), LZMA (.lzma), LZOP (.lzo), RPM (.rpm), RAR (.rar), RZIP (.rz), TAR (.tar), XZ (.xz), ZIP (.zip, .jar) and ZOO (.zoo)
patool is called by pyunpack using its command line interface. If patool is not installed then only zip format can be unpacked using the internal python zipfile library.
$ echo hello > hello.txt
$ zip hello.zip hello.txt
$ rm hello.txt
$ python3
>>> from pyunpack import Archive
>>> Archive('hello.zip').extractall('.')
>>> open('hello.txt').read()
'hello\n'
using command line interface:
$ echo hello > hello.txt
$ zip hello.zip hello.txt
$ rm hello.txt
$ python3 -m pyunpack.cli hello.zip .
$ cat hello.txt
hello
$ sudo apt-get install unzip unrar p7zip-full
$ python3 -m pip install patool
$ python3 -m pip install pyunpack
$ python3 -m pyunpack.cli --help
usage: cli.py [-h] [-b BACKEND] [-a] [--debug] filename directory
positional arguments:
filename path to archive file
directory directory to extract to
options:
-h, --help show this help message and exit
-b BACKEND, --backend BACKEND
auto, patool or zipfile
-a, --auto-create-dir
auto create directory
--debug set logging level to DEBUG