Skip to content
/ py7zr Public

7zip in python3 with ZStandard, PPMd, LZMA2, LZMA1, Delta, BCJ, BZip2, and Deflate compressions, and AES encryption.

License

Notifications You must be signed in to change notification settings

miurahr/py7zr

Repository files navigation

py7zr

https://readthedocs.org/projects/py7zr/badge/?version=latest https://travis-ci.org/miurahr/py7zr.svg?branch=master https://ci.appveyor.com/api/projects/status/966k084122lhs3i6?svg=true https://dev.azure.com/miurahr/github/_apis/build/status/miurahr.py7zr?branchName=master https://coveralls.io/repos/github/miurahr/py7zr/badge.svg?branch=master

Pure python 7-zip implementation

Dependency

It uses a standard lzma module and its API supported. It also uses type definitions introduced in Python3.6.

Minimum required version is Python 3.5.

Version recommendations are:

  • CPython 3.7.5, CPython 3.8.0 and later.
  • PyPy3.6-7.2.0 and later.

Following fixes are included in above versions and python3.6 series is not fixed it.

  • BPO-21872: LZMA library sometimes fails to decompress a file
  • PyPy3-3088: lzma.LZMADecomporessor.decompress does not respect max_length

Document

Here is a readthedocs manual document.

Usage

You can run command script py7zr like as follows;

$ py7zr l test.7z
$ py7zr x test.7z
$ py7zr w target.7z test_dir

py7zr is a library which can use in your pyhton application. Here is a code snippet how to decompress some file in your applicaiton.

import py7zr

archive = py7zr.SevenZipFile('sample.7z', mode='r')
archive.extractall(path="/tmp")
archive.close()

Here is a code snippet how to produce archive.

import py7zr

archvie = py7zr.SevenZipFile('target.7z', 'w')
archive.writeall('./base_dir')
archive.close()

py7zr also support shutil interface.

from py7zr import pack_7zarchvie, 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')

License

  • Copyright (C) 2019 Hiroshi Miura
  • 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 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