/pyunpack

unpack archive files in python

Primary LanguagePythonBSD 2-Clause "Simplified" LicenseBSD-2-Clause

unpack archive files in Python

Links:

workflow

Features:

  • unpack archive files
  • support passwords
  • very simple interface
  • command line interface and library
  • supported python versions: 3.9, 3.10, 3.11, 3.12
  • 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)

Functionality

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.

Usage

$ 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

Installation on Ubuntu

$ sudo apt-get install unzip unrar p7zip-full
$ python3 -m pip install pyunpack

Currently (2022) Patool latest pip release is from 2016 (https://pypi.org/project/patool/#history), so it is recommended to install it from github until it is not updated. Password support was added in 2020

$ python3 -m pip install https://github.com/wummel/patool/archive/refs/heads/master.zip

command line help

$ python3 -m pyunpack.cli --help
usage: cli.py [-h] [-b BACKEND] [-p PASSWORD] [-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
  -p PASSWORD, --password PASSWORD
  -a, --auto-create-dir
                        auto create directory
  --debug               set logging level to DEBUG