Package: py7zr
py7zr is a library and utility to support 7zip archive compression, decompression,
encryption and decryption written by Python programming language.Security NoticeVersion 0.20.0, 0.19.0, 0.18.10 or before has avulnerability for path traversalattack.
Details are on “CVE-2022-44900: path traversal vulnerability in py7zr”disclose article.Affected versions  are vulnerable to Directory Traversal due to insufficient checks in the ‘py7zr.py’ and ‘helpers.py’ filesYou are recommend to update immediately to version 0.20.2 or later, 0.19.2 or 0.18.12I realy appreciate Mr. Matteo Cosentino for notification and coorporation on security improvement.Compression algorithmspy7zrsupports algorithms and filters whichlzma moduleandliblzmasupport,
and supports BZip2 and Deflate that are implemented in python core libraries,
It also supports ZStandard, Brotli and PPMd with third party libraries.py7zris also able to encrypt and decrypt data using 3rd party encryption library.Supported algorithmscompressLZMA2LZMABzip2DeflateCopyZStandardBrotliPPMdEnhanced Deflate (Experimental)crypt7zAESFiltersDeltaBCJ(X86,ARMT,ARM,PPC,SPARC,IA64)NoteA feature handling symbolic link is basically compatible withp7zipimplementation,
but not work with original 7-zip because the original does not implement the feature.py7zrtry checking symbolic links strictly and raise ValueError when bad link is requested,
but it doesnotguarantee to block all the bad cases.ZStandard and Brotli is not default methods of 7-zip, so these archives are considered
not to be compatible with original 7-zip on windows/p7zip on linux/mac.Enhanced Deflate is also known asDEFLATE64TMthat is a registered trademark ofPKWARE, Inc.Enhanced Deflate is tested only on CPython. It is disabled on PyPy.Not supported algorithmsBCJ2 (Standardlzma moduledoes not provide).InstallYou can install py7zr as usual other libraries using pip.$pipinstallpy7zrOR, alternatively using conda:$condainstall-cconda-forgepy7zrDocumentsUser manualsUser Guidefor latest version.API Guidefor latest version.Manualfor stable version.Developer guideContributor guidefor one want to contribute the project.7z file specificationCLI UsageYou can run command script py7zr like as follows;List archive contents$py7zrltest.7zExtract archive$py7zrxtest.7zExtract archive with password$py7zrx-Ptest.7zpassword?:****Create and compress to archive$py7zrctarget.7ztest_dirCreate multi-volume archive$py7zrc-v500ktarget.7ztest_dirTest archive$py7zrttest.7zAppend files to archive$py7zratest.7ztest_dirShow information$py7zriShow version$py7zr--versionSevenZipFile Class Usagepy7zr is a library which can use in your python application.Decompression/DecryptionHere is a code snippet how to decompress some file in your application.importpy7zrarchive=py7zr.SevenZipFile('sample.7z',mode='r')archive.extractall(path="/tmp")archive.close()You can also use ‘with’ block because py7zr provide context manager(v0.6 and later).importpy7zrwithpy7zr.SevenZipFile('sample.7z',mode='r')asz:z.extractall()withpy7zr.SevenZipFile('target.7z','w')asz:z.writeall('./base_dir')py7zralso supports extraction of single or selected files by ‘extract(targets=[‘file path’])’.
Note: if you specify only a file but not a parent directory, it will fail.importpy7zrimportrefilter_pattern=re.compile(r'<your/target/file_and_directories/regex/expression>')withpy7zr.SevenZipFile('archive.7z','r')asarchive:allfiles=archive.getnames()selective_files=[fforfinallfilesiffilter_pattern.match(f)]archive.extract(targets=selective_files)py7zr support an extraction of password protected archive.(v0.6 and later)importpy7zrwithpy7zr.SevenZipFile('encrypted.7z',mode='r',password='secret')asz:z.extractall()Compression/EncryptionHere is a code snippet how to produce archive.importpy7zrwithpy7zr.SevenZipFile('target.7z','w')asarchive:archive.writeall('/path/to/base_dir','base')To create encrypted archive, please pass a password.importpy7zrwithpy7zr.SevenZipFile('target.7z','w',password='secret')asarchive:archive.writeall('/path/to/base_dir','base')To create archive with algorithms such as zstandard, you can call with custom filter.importpy7zrmy_filters=[{"id":py7zr.FILTER_ZSTD}]another_filters=[{"id":py7zr.FILTER_ARM},{"id":py7zr.FILTER_LZMA2,"preset":7}]withpy7zr.SevenZipFile('target.7z','w',filters=my_filters)asarchive:archive.writeall('/path/to/base_dir','base')shutil helperpy7zr also supportshutilinterface.frompy7zrimportpack_7zarchive,unpack_7zarchiveimportshutil# register file format at first.shutil.register_archive_format('7zip',pack_7zarchive,description='7zip archive')shutil.register_unpack_format('7zip',['.7z'],unpack_7zarchive)# extractionshutil.unpack_archive('test.7z','/tmp')# compressionshutil.make_archive('target','7zip','src')Requirementspy7zruses a python3 standardlzma modulefor extraction and compression.
The standard lzma module usesliblzmathat support core compression algorithm of 7zip.Minimum required version is Python 3.7.py7zrtested on Linux, macOS, Windows and Ubuntu aarch64.It hopefully works on M1 Mac too.Recommended versions are:CPython 3.7.5, CPython 3.8.0 and later.PyPy3.7-7.3.3 and later.Following fixes are included in these versions, and it is not fixed on python3.6.BPO-21872: LZMA library sometimes fails to decompress a filePyPy3-3090: lzma.LZMADecomporessor.decompress does not respect max_lengthPyPy3-3242: ‘_lzma_cffi’ has no function named ‘lzma_stream_encoder’Following improvements are included in CPython 3.10BPO-41486: Faster bz2/lzma/zlib via new output bufferingDependenciesThere are several dependencies to support algorithms and CLI expressions.PackagePurposePyCryptodomex7zAES encryptionPyZstdZStandard compressionPyPPMdPPMd compressionBrotliBrotli compression (CPython)BrotliCFFIBrotli compression (PyPy)inflate64Enhanced deflate compressionpybcjBCJ filtersmultivolumefileMulti-volume archive read/writetexttableCLI formatterPerformanceYou can find a compression and decompression benchmark results at
[Github issue](https://github.com/miurahr/py7zr/issues/297) and [wiki page](https://github.com/miurahr/py7zr/wiki/Benchmarks)py7zr works well, but slower than7-zipandp7zipC/C++ implementation by several reasons.
When compression/decompressionspeedis important, it is recommended to use these
alternatives throughsubprocess.runpython interface.py7zr consumes some memory to decompress and compress data. It requires about 300MiB - 700MiB free memory to work well at least.Use CasesaqtinstallAnother (unofficial) Qt (aqt) CLI Installer on multi-platforms.PreNLPPreprocessing Library for Natural Language Processingmloxa tool for sorting and analyzing Morrowind plugin load orderLicenseCopyright (C) 2019-2022 Hiroshi Miurapylzma Copyright (c) 2004-2015 by Joachim Bauch7-Zip Copyright (C) 1999-2010 Igor PavlovLZMA SDK Copyright (C) 1999-2010 Igor PavlovThis library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA