py7zr 1.0.0


pip install py7zr

  Latest version

Released: Jun 02, 2025


Meta
Author: Hiroshi Miura
Requires Python: >=3.9

Classifiers

Development Status
  • 5 - Production/Stable

License
  • OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)

Operating System
  • MacOS :: MacOS X
  • Microsoft :: Windows
  • POSIX
  • POSIX :: Linux

Programming Language
  • Python
  • Python :: 3
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3 :: Only
  • Python :: Implementation :: CPython
  • Python :: Implementation :: PyPy

Topic
  • Software Development :: Libraries :: Python Modules
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 Codacy

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

Incompatible change

There is incompatible change between v1.0.0-rc1 to v1.0.0-rc2. I abandon methods read and readall. When you want to extract the archive to memory, you need to use extract method with factory argument. The factory takes a factory class, as of the GoF design pattern, that provides object implements Py7zIO interface as a call back instance. SevenZipFile extract and write uncompressed data into your Py7zIO object.

Discussion Forum

You are welcome to join discussions on project forum/builtin-board at https://github.com/miurahr/py7zr/discussions

You can see announcements of new releases, questions and answers, and new feature ideas. When you doubt for usage of py7zr library with unclear manuals, please feel easy to raise question on forum.

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

    • PPMd

    • Enhanced Deflate (Experimental)

  • crypt
    • 7zAES

  • Filters
    • Delta

    • BCJ(X86,ARMT,ARM,PPC,SPARC,IA64)

Not supported algorithms

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

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.

Decompression/Decryption

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

import py7zr

archive = 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).

import py7zr

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

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

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 py7zr.SevenZipFile('archive.7z', 'r') as archive:
    allfiles = archive.getnames()
    selective_files = [f for f in allfiles if filter_pattern.match(f)]
    archive.extract(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') as z:
    z.extractall()

Compression/Encryption

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_filters) 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')

Requirements

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.9.

py7zr tested on Linux, macOS, Windows and Ubuntu aarch64.

It hopefully works on M1 Mac too.

Recommended versions are:

  • CPython 3.9.0 and later.

  • PyPy3.9-7.3.8 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 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

Dependencies

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)

inflate64

Enhanced deflate compression

pybcj

BCJ filters

multivolumefile

Multi-volume archive read/write

texttable

CLI formatter

Performance

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

  • PyTorch Open-source deep learning framework.

  • 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

Security

Please find a Security Policy of this project.

Version 0.20.0, 0.19.0, 0.18.10 or before has a vulnerability for path traversal attack. 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’ files

You are recommend to update immediately to version 0.20.2 or later

I really appreciate Mr. Matteo Cosentino for notification and corporation on security improvement.

License

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

1.0.0 Jun 02, 2025
1.0.0rc3 May 15, 2025
1.0.0rc2 Dec 23, 2024
1.0.0rc1 Aug 08, 2024
0.22.0 Aug 08, 2024
0.21.1 Jul 01, 2024
0.21.0 Mar 02, 2024
0.20.8 Nov 13, 2023
0.20.7 Nov 05, 2023
0.20.6 Aug 05, 2023
0.20.5 Apr 15, 2023
0.20.4 Feb 10, 2023
0.20.2 Nov 02, 2022
0.20.1 Nov 01, 2022
0.20.0 Aug 02, 2022
0.19.2 Nov 03, 2022
0.19.1 Nov 01, 2022
0.19.0 Jul 02, 2022
0.18.12 Nov 03, 2022
0.18.11 Nov 01, 2022
0.18.10 Jul 02, 2022
0.18.9 Jun 04, 2022
0.18.7 Jun 01, 2022
0.18.6 May 17, 2022
0.18.5 Apr 22, 2022
0.18.4 Apr 17, 2022
0.18.3 Mar 26, 2022
0.18.1 Mar 12, 2022
0.18.0 Mar 08, 2022
0.17.4 Feb 09, 2022
0.17.3 Jan 24, 2022
0.17.2 Dec 15, 2021
0.17.1 Dec 15, 2021
0.17.0 Dec 04, 2021
0.16.4 Dec 01, 2021
0.16.3 Nov 14, 2021
0.16.2 Oct 15, 2021
0.16.1 May 07, 2021
0.16.0 May 04, 2021
0.15.2 Apr 29, 2021
0.15.1 Apr 07, 2021
0.15.0 Apr 04, 2021
0.14.1 Feb 28, 2021
0.14.0 Feb 25, 2021
0.13.1 Feb 28, 2021
0.13.0 Feb 19, 2021
0.12.0 Feb 04, 2021
0.11.3 Jan 20, 2021
0.11.2 Jan 19, 2021
0.11.1 Dec 08, 2020
0.11.0 Nov 03, 2020
0.11.0b3 Oct 18, 2020
0.11.0b2 Oct 15, 2020
0.11.0b1 Oct 13, 2020
0.11.0a1 Oct 05, 2020
0.10.2 Jan 20, 2021
0.10.1 Oct 05, 2020
0.10.0 Oct 04, 2020
0.10.0b3 Oct 04, 2020
0.10.0b1 Sep 19, 2020
0.10.0a6 Sep 12, 2020
0.10.0a5 Aug 30, 2020
0.10.0a4 Aug 30, 2020
0.10.0a3 Aug 29, 2020
0.10.0a2 Aug 11, 2020
0.10.0a1 Aug 09, 2020
0.9.10 Jan 20, 2021
0.9.9 Oct 04, 2020
0.9.8 Oct 04, 2020
0.9.7 Sep 12, 2020
0.9.5 Aug 11, 2020
0.9.4 Aug 10, 2020
0.9.3 Aug 09, 2020
0.9.2 Aug 04, 2020
0.9.1 Aug 01, 2020
0.9.0 Aug 01, 2020
0.9.0b3 Jul 21, 2020
0.9.0b2 Jul 19, 2020
0.9.0b1 Jul 18, 2020
0.9.0a2 Jul 15, 2020
0.9.0a1 Jul 05, 2020
0.8.5 Aug 08, 2020
0.8.4 Aug 01, 2020
0.8.3 Jul 21, 2020
0.8.2 Jul 15, 2020
0.8.1 Jul 09, 2020
0.8.0 Jul 04, 2020
0.8.0b8 Jun 29, 2020
0.8.0b7 Jun 23, 2020
0.8.0b6 Jun 22, 2020
0.8.0b5 Jun 19, 2020
0.8.0b4 Jun 17, 2020
0.8.0b3 Jun 15, 2020
0.8.0b2 Jun 14, 2020
0.8.0b1 Jun 13, 2020
0.8.0a3 Jun 13, 2020
0.8.0a2 Jun 08, 2020
0.8.0a1 Jun 04, 2020
0.7.4 Jun 15, 2020
0.7.3 Jun 03, 2020
0.7.2 Jun 01, 2020
0.7.1 May 31, 2020
0.7.0 May 24, 2020
0.7.0b3 May 23, 2020
0.7.0b2 May 09, 2020
0.7.0b1 May 08, 2020
0.6 Mar 12, 2020
0.6rc0 Mar 11, 2020
0.6b8 Mar 02, 2020
0.6b7 Feb 29, 2020
0.6b6 Feb 27, 2020
0.6b5 Feb 26, 2020
0.6b4 Feb 19, 2020
0.6b3 Feb 18, 2020
0.6b2 Feb 15, 2020
0.6b1 Feb 14, 2020
0.6a2 Feb 13, 2020
0.6a1 Feb 03, 2020
0.5.5 Mar 09, 2020
0.5.4 Mar 02, 2020
0.5.3 Feb 26, 2020
0.5.2 Feb 19, 2020
0.5 Feb 13, 2020
0.5rc3 Feb 12, 2020
0.5rc2 Feb 03, 2020
0.5b6 Jan 25, 2020
0.5b5 Jan 09, 2020
0.5b4 Jan 09, 2020
0.5b3 Dec 22, 2019
0.5b2 Dec 19, 2019
0.5b1 Dec 12, 2019
0.5a4 Dec 07, 2019
0.5a3 Dec 07, 2019
0.4.4 Nov 27, 2019
0.4.3 Nov 27, 2019
0.4.1 Nov 10, 2019
0.4 Oct 24, 2019
0.4b1 Oct 12, 2019
0.4a2 Oct 12, 2019
0.4a1 Oct 10, 2019
0.3.5 Oct 08, 2019
0.3.4 Sep 30, 2019
0.3.3 Sep 14, 2019
0.3.2 Jun 28, 2019
0.3.1 Jun 23, 2019
0.3 Jun 19, 2019
0.2.0 Jun 03, 2019
0.1.6 Jun 03, 2019
0.1.5 Jun 01, 2019
0.1.4 Jun 01, 2019
0.1.3 May 28, 2019
0.1.2 May 27, 2019
0.1.1 May 03, 2019
0.1.0 May 01, 2019
0.0.8 Apr 28, 2019
0.0.7 Apr 27, 2019
0.0.6 Apr 26, 2019
0.0.5 Apr 26, 2019
0.0.4 Apr 23, 2019
0.0.3 Apr 22, 2019

Wheel compatibility matrix

Platform Python 3
any

Files in release

Extras:
Dependencies:
texttable
pycryptodomex (>=3.20.0)
brotli (>=1.1.0)
brotlicffi (>=1.1.0.0)
psutil
pyzstd (>=0.16.1)
pyppmd (<1.3.0,>=1.1.0)
pybcj (<1.1.0,>=1.0.0)
multivolumefile (>=0.2.3)
inflate64 (<1.1.0,>=1.0.0)