loongson/pypi/: py7zr-0.18.9 metadata and description

Homepage Simple index

Pure python 7-zip library

author Hiroshi Miura
author_email Hiroshi Miura <miurahr@linux.com>
  • Development Status :: 4 - Beta
  • License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
  • Operating System :: MacOS :: MacOS X
  • Operating System :: Microsoft :: Windows
  • Operating System :: POSIX
  • Operating System :: POSIX :: Linux
  • Programming Language :: Python
  • Programming Language :: Python :: 3
  • Programming Language :: Python :: 3.6
  • Programming Language :: Python :: 3.7
  • Programming Language :: Python :: 3.8
  • Programming Language :: Python :: 3.9
  • Programming Language :: Python :: 3.10
  • Programming Language :: Python :: 3 :: Only
  • Programming Language :: Python :: Implementation :: CPython
  • Programming Language :: Python :: Implementation :: PyPy
  • Topic :: Software Development :: Libraries :: Python Modules
description_content_type text/x-rst
keywords compression,7zip,lzma,zstandard,ppmd,lzma2,bcj,archive
license LGPL-2.1-or-later
  • Homepage, https://py7zr.readthedocs.io/
  • Documentation, https://py7zr.readthedocs.io/en/stable/
  • Bug Tracker, https://github.com/miurahr/py7zr/issues
  • Source, https://github.com/miurahr/py7zr
  • Changelog, https://github.com/miurahr/py7zr/blob/master/Changelog.rst
provides_extras test_compat
  • texttable
  • pycryptodomex (>=3.6.6)
  • psutil
  • pyzstd (>=0.14.4)
  • pyppmd (<0.19.0,>=0.18.1)
  • pybcj (>=0.6.0)
  • multivolumefile (>=0.2.3)
  • zipfile-deflate64 (>=0.2.0)
  • brotli (>=1.0.9) ; platform_python_implementation == "CPython"
  • brotlicffi (>= ; platform_python_implementation == "PyPy"
  • importlib-metadata ; python_version < "3.8"
  • mypy (>=0.940) ; extra == 'check'
  • mypy-extensions (>=0.4.1) ; extra == 'check'
  • check-manifest ; extra == 'check'
  • flake8 ; extra == 'check'
  • flake8-black ; extra == 'check'
  • flake8-deprecated ; extra == 'check'
  • isort (>=5.0.3) ; extra == 'check'
  • pygments ; extra == 'check'
  • readme-renderer ; extra == 'check'
  • twine ; extra == 'check'
  • pytest ; extra == 'debug'
  • pytest-leaks ; extra == 'debug'
  • pytest-profiling ; extra == 'debug'
  • sphinx (>=5.0) ; extra == 'docs'
  • sphinx-py3doc-enhanced-theme ; extra == 'docs'
  • sphinx-a4doc ; extra == 'docs'
  • docutils ; extra == 'docs'
  • pytest ; extra == 'test'
  • pytest-benchmark ; extra == 'test'
  • pytest-cov ; extra == 'test'
  • pytest-remotedata ; extra == 'test'
  • pytest-timeout ; extra == 'test'
  • pyannotate ; extra == 'test'
  • py-cpuinfo ; extra == 'test'
  • coverage[toml] (>=5.2) ; extra == 'test'
  • coveralls (>=2.1.1) ; extra == 'test'
  • libarchive-c ; extra == 'test_compat'
requires_python >=3.6

Because this project isn't in the mirror_whitelist, no releases from root/pypi are included.

File Tox results History
63 KB
Python Wheel
https://readthedocs.org/projects/py7zr/badge/?version=latest https://badge.fury.io/py/py7zr.svg https://img.shields.io/pypi/dd/py7zr https://img.shields.io/conda/vn/conda-forge/py7zr https://github.com/miurahr/py7zr/workflows/Run%20Tox%20tests/badge.svg https://dev.azure.com/miurahr/github/_apis/build/status/miurahr.py7zr?branchName=master https://coveralls.io/repos/github/miurahr/py7zr/badge.svg?branch=master https://img.shields.io/pypi/l/py7zr https://raw.githubusercontent.com/vshymanskyy/StandWithUkraine/main/badges/StandWithUkraine.svg

py7zr is a library and utility to support 7zip archive compression, decompression, encryption and decryption written by Python programming language.

Compression algorithms

py7zr supports algorithms and filters which lzma module and liblzma support, and supports BZip2 and Deflate that are implemented in python core libraries, It also supports ZStandard, Brotli and PPMd with third party libraries.

py7zr is also able to encrypt and decrypt data using 3rd party encryption library.

Supported algorithms

  • compress
    • LZMA2
    • LZMA
    • Bzip2
    • Deflate
    • Copy
    • ZStandard
    • Brotli
    • Deflate64 (Decompression only)
    • PPMd (Experimental)
  • crypt
    • 7zAES
  • Filters
    • Delta


  • A feature handling symbolic link is basically compatible with p7zip implementation, but not work with original 7-zip because the original does not implement the feature.
  • 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.

Not supported algorithms


You can install py7zr as usual other libraries using pip.

$ pip install py7zr

OR, alternatively using conda:

$ conda install -c conda-forge py7zr


User manuals

Developer guide

CLI Usage

You can run command script py7zr like as follows;

  • List archive contents
$ py7zr l test.7z
  • Extract archive
$ py7zr x test.7z
  • Extract archive with password
$ py7zr x -P test.7z
  password?: ****
  • Create and compress to archive
$ py7zr c target.7z test_dir
  • Create multi-volume archive
$ py7zr c -v 500k target.7z test_dir
  • Test archive
$ py7zr t test.7z
  • Append files to archive
$ py7zr a test.7z test_dir
  • Show information
$ py7zr i
  • Show version
$ py7zr --version

SevenZipFile Class Usage

py7zr is a library which can use in your python application.


Here is a code snippet how to decompress some file in your application.

import py7zr

archive = py7zr.SevenZipFile('sample.7z', mode='r')

You can also use ‘with’ block because py7zr provide context manager(v0.6 and later).

import py7zr

with py7zr.SevenZipFile('sample.7z', mode='r') as z:

with py7zr.SevenZipFile('target.7z', 'w') as z:

py7zr also 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.

import py7zr
import re

filter_pattern = re.compile(r'<your/target/file_and_directories/regex/expression>')
with SevenZipFile('archive.7z', 'r') as archive:
    allfiles = archive.getnames()
    selective_files = [f for f in allfiles if filter_pattern.match(f)]

py7zr support an extraction of password protected archive.(v0.6 and later)

import py7zr

with py7zr.SevenZipFile('encrypted.7z', mode='r', password='secret') as z:


Here is a code snippet how to produce archive.

import py7zr

with py7zr.SevenZipFile('target.7z', 'w') as archive:
    archive.writeall('/path/to/base_dir', 'base')

To create encrypted archive, please pass a password.

import py7zr

with py7zr.SevenZipFile('target.7z', 'w', password='secret') as archive:
    archive.writeall('/path/to/base_dir', 'base')

To create archive with algorithms such as zstandard, you 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:
    archive.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')


py7zr uses a python3 standard lzma module for extraction and compression. The standard lzma module uses liblzma that support core compression algorithm of 7zip.

Minimum required version is Python 3.6.

py7zr tested 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.6-7.3.2 and later.
  • CPython 3.10.0 is supported from py7zr v0.17.0

Following fixes are included in these versions, and it is not fixed on python3.6.

  • 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


There are several dependencies to support algorithms and CLI expressions.

Package Purpose
PyCryptodomex 7zAES encryption
PyZstd ZStandard compression
PyPPMd PPMd compression
Brotli Brotli compression (CPython)
BrotliCFFI Brotli compression (PyPy)
zipfile-deflate64 DEFLATE64 decompression
pybcj BCJ filters
multivolumefile Multi-volume archive read/write
texttable CLI formatter


You 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 than 7-zip and p7zip C/C++ implementation by several reasons. When compression/decompression speed is important, it is recommended to use these alternatives through subprocess.run python interface.

py7zr consumes some memory to decompress and compress data. It requires about 300MiB - 700MiB free memory to work well at least.

Use Cases

  • aqtinstall Another (unofficial) Qt (aqt) CLI Installer on multi-platforms.
  • PreNLP Preprocessing Library for Natural Language Processing
  • mlox a tool for sorting and analyzing Morrowind plugin load order


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