Upload Zip Files Using Poster Library Python
py7zr is a library and utility to support 7zip archive pinch, decompression, encryption and decryption written by Python programming linguistic communication.
Install
You can install py7zr as usual other libraries using pip.
$ pip install py7zr
OR, alternatively using conda:
$ conda install -c conda-forge py7zr
Documents
CLI Usage
You lot can run command script py7zr like equally follows;
- Listing archive contents
$ py7zr l test.7z
- Extract archive
$ py7zr x test.7z
- Extract archive with countersign
$ py7zr x -P test.7z password?: ****
- Create and compress to archive
$ py7zr c target.7z test_dir
- Create multi-book annal
$ py7zr c -v 500k target.7z test_dir
- Test annal
$ py7zr t exam.7z
- Append files to annal
$ py7zr a test.7z test_dir
- Evidence information
$ py7zr i
- Bear witness version
$ py7zr --version
SevenZipFile Course Usage
py7zr is a library which tin apply in your python application.
Decompression/Decryption
Here is a lawmaking snippet how to decompress some file in your application.
import py7zr archive = py7zr . SevenZipFile ( 'sample.7z' , way = 'r' ) archive . extractall ( path = "/tmp" ) archive . close ()
Y'all tin also use 'with' block because py7zr provide context managing director(v0.six and afterward).
import py7zr with py7zr . SevenZipFile ( 'sample.7z' , style = 'r' ) equally z : z . extractall () with py7zr . SevenZipFile ( 'target.7z' , 'due west' ) as z : z . writeall ( './base_dir' )
py7zr too supports extraction of single or selected files by 'extract(targets=['file path'])'. Note: if yous specify only a file simply not a parent directory, it will fail.
import py7zr import re filter_pattern = re . compile ( r '<your/target/file_and_directories/regex/expression>' ) with SevenZipFile ( 'archive.7z' , 'r' ) equally archive : allfiles = archive . getnames () selective_files = [ f for f in allfiles if filter_pattern . friction match ( f )] archive . excerpt ( targets = selective_files )
py7zr support an extraction of password protected archive.(v0.6 and later)
import py7zr with py7zr . SevenZipFile ( 'encrypted.7z' , mode = 'r' , password = 'secret' ) equally z : z . extractall ()
Compression/Encryption
Hither is a code snippet how to produce archive.
import py7zr with py7zr . SevenZipFile ( 'target.7z' , 'w' ) as archive : annal . writeall ( '/path/to/base_dir' , 'base' )
To create encrypted annal, delight pass a countersign.
import py7zr with py7zr . SevenZipFile ( 'target.7z' , 'west' , password = 'secret' ) as archive : annal . writeall ( '/path/to/base_dir' , 'base' )
To create archive with algorithms such as zstandard, you tin can call with custom filter.
import py7zr my_filters = [{ "id" : py7zr . FILTER_ZSTD }] another_filters = [{ "id" : py7zr . FILTER_ARM }, { "id" : py7zr . FILTER_LZMA2 , "preset" : 7 }] with py7zr . SevenZipFile ( 'target.7z' , 'w' , filters = my_filter ) as archive : annal . writeall ( '/path/to/base_dir' , 'base' )
shutil helper
py7zr also support shutil interface.
from py7zr import pack_7zarchive , unpack_7zarchive import shutil # register file format at first. shutil . register_archive_format ( '7zip' , pack_7zarchive , description = '7zip archive' ) shutil . register_unpack_format ( '7zip' , [ '.7z' ], unpack_7zarchive ) # extraction shutil . unpack_archive ( 'test.7z' , '/tmp' ) # compression shutil . make_archive ( 'target' , '7zip' , 'src' )
Requirements
py7zr uses a python3 standard lzma module for extraction and compression. The standard lzma module uses liblzma that support core pinch algorithm of 7zip.
Minimum required version is Python 3.six.
py7zr tested on Linux, macOS, Windows and Ubuntu aarch64.
It hopefully works on M1 Mac likewise.
Recommended versions are:
- CPython 3.7.five, CPython 3.8.0 and afterward.
- PyPy3.6-vii.iii.2 and later.
- CPython 3.10.0 is supported from py7zr v0.17.0
Post-obit fixes are included in these versions, and it is not fixed on python3.half-dozen.
- BPO-21872: LZMA library sometimes fails to decompress a file
- PyPy3-3090: lzma.LZMADecomporessor.decompress does not respect max_length
- PyPy3-3242: '_lzma_cffi' has no function named 'lzma_stream_encoder'
Following improvements are included in CPython 3.10
- BPO-41486: Faster bz2/lzma/zlib via new output buffering
Pinch Methods supported
'py7zr' supports algorithms and filters which lzma module and liblzma support. Information technology also back up BZip2 and Deflate that are implemented in python core libraries, and ZStandard with 3rd party libraries.
Supported algorithms are:
-
- compress
-
- LZMA2
- LZMA
- Bzip2
- Deflate
- Copy
- ZStandard
- Brotli
- Deflate64 (Decompression only)
- PPMd (Experimental)
-
- catacomb
-
- 7zAES
-
- Filters
-
- Delta
- BCJ(X86,ARMT,ARM,PPC,SPARC,IA64)
-
- No support
-
- BCJ2
- A characteristic handling symbolic link is basically uniform with 'p7zip' implementation, only not work with original 7-zip because the original does not implement the feature.
- ZStandard and Brotli is not default methods of 7-zip, and then these archives are considered non to exist uniform with original 7-zip on windows/p7zip on linux/mac.
- liblzma, which Python's standard lzma module depends, does not provide BCJ2 filter.
- Deflate64 is proprietary algorithm.
Use Cases
- aqtinstall Another (unofficial) Qt (aqt) CLI Installer on multi-platforms.
- PreNLP Preprocessing Library for Natural Linguistic communication Processing
- mlox a tool for sorting and analyzing Morrowind plugin load lodge
License
- Copyright (C) 2019-2021 Hiroshi Miura
- pylzma Copyright (c) 2004-2015 by Joachim Bauch
- 7-Zip Copyright (C) 1999-2010 Igor Pavlov
- LZMA SDK Copyright (C) 1999-2010 Igor Pavlov
This library is complimentary software; y'all can redistribute information technology and/or modify it under the terms of the GNU Lesser General Public License as published by the Gratuitous Software Foundation; either version 2.one of the License, or (at your pick) whatever later version.
This library is distributed in the promise that it will exist useful, but WITHOUT ANY WARRANTY; without fifty-fifty the implied warranty of MERCHANTABILITY or FITNESS FOR A Item 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 Costless Software Foundation, Inc., 51 Franklin Street, 5th Floor, Boston, MA 02110-1301 USA
WARNING
Test archive data, which affected a malware, have been existed from Aug, 2020 - 20, Jan, 2021!
All the git history is re-writed, and so please remove your local and fork copy of the git repository, and clone again(if necessary)!
Problematic file is named issue_218.7z and issue_218_2.7z.
In that location is NO affected in library itself. and the test execution besides does not excerpt the malware file. There is no problem when you install py7zr with pip control.
Release that has a clean source:
- v0.11.iii and afterward
- v0.10.2
- v0.9.10
- v0.9.4 and before
Source: https://pypi.org/project/py7zr/
0 Response to "Upload Zip Files Using Poster Library Python"
Enviar um comentário