Install & Compatibility
Where this runs
tested against v1.1.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.248s · 34MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.2s · import 0.242s · 36MB
34MB installed
● package 34MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SevenZipFile
✓ from py7zr import SevenZipFile
is_7zfile
✓ from py7zr import is_7zfile
This quickstart demonstrates how to create a 7z archive with a single file and then extract its contents to a new directory. It includes basic error handling and cleanup.
import py7zr
import os
archive_name = "example.7z"
file_to_archive = "test_file.txt"
# Create a dummy file for archiving
with open(file_to_archive, "w") as f:
f.write("This is a test file for py7zr.\n")
try:
# Create a 7z archive
with py7zr.SevenZipFile(archive_name, 'w') as archive:
archive.write(file_to_archive, arcname='renamed_test_file.txt')
print(f"Archive '{archive_name}' created with '{file_to_archive}'.")
# Extract from the 7z archive
extract_dir = "extracted_files"
os.makedirs(extract_dir, exist_ok=True)
with py7zr.SevenZipFile(archive_name, mode='r') as archive:
archive.extractall(path=extract_dir)
print(f"Files extracted to '{extract_dir}'.")
# Verify extraction
extracted_path = os.path.join(extract_dir, 'renamed_test_file.txt')
if os.path.exists(extracted_path):
with open(extracted_path, 'r') as f:
content = f.read()
print(f"Content of extracted file: {content.strip()}")
else:
print("Extraction verification failed.")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Clean up created files and directories
if os.path.exists(file_to_archive):
os.remove(file_to_archive)
if os.path.exists(archive_name):
os.remove(archive_name)
if os.path.exists(extract_dir):
for root, dirs, files in os.walk(extract_dir, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
os.rmdir(os.path.join(root, name))
os.rmdir(extract_dir)
print("Cleanup complete.")
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'py7zr'
The `py7zr` library is not installed in the current Python environment, or the Python environment where it's installed is not active.
fixInstall the library using pip: `pip install py7zr`. If you are using a virtual environment, ensure it is activated before running the installation command.
py7zr.Bad7zFile: not a 7z file
The file being opened is either not a valid 7-Zip archive, is corrupted, or has an incorrect file extension and `py7zr` cannot recognize its format.
fixEnsure the file is a legitimate and uncorrupted `.7z` archive. You can use `py7zr.is_7zfile('your_file.7z')` to pre-check if a file is a valid 7z archive before attempting to open it. py7zr.PasswordRequired
An attempt was made to extract an encrypted 7-Zip archive without providing the correct password, or an incorrect password was supplied.
fixProvide the correct password when initializing the `SevenZipFile` object: `with py7zr.SevenZipFile('archive.7z', mode='r', password='your_password') as archive:`. KeyError: 'filename_not_found'
This error occurs when trying to get information about or extract a file (e.g., using `getinfo()` or `extract()`) that does not exist within the 7-Zip archive under the specified name or path.
fixVerify the exact filename and its path within the archive. You can list all member names using `archive.getnames()` to ensure the target file exists and its name is correctly spelled.
TypeError: argument of type 'str' is not iterable
The `targets` argument in `extract()` or `extractall()` methods expects an iterable (like a list or set) of filenames, but a single string was provided directly.
fixWrap the single filename in a list, even if extracting only one file: `archive.extract(targets=['single_file.txt'])`.
Upgrade
Version history
1.1.3latest on PyPI · released Jun 19, 2026
Audit
Dependencies
No dependency data recorded yet.