Install & Compatibility
Where this runs
tested against v2.2.1 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.048s · 17.9MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.044s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
RPMFile
✓ from rpmfile import RPMFile
This quickstart demonstrates how to open an RPM file using `rpmfile.open()`, access its headers, and list its members. A dummy RPM file is created for demonstration, but for full functionality, a real RPM file should be used.
import rpmfile
import os
# NOTE: Replace 'path/to/your/file.rpm' with an actual RPM file path.
# For a runnable example, you'd typically download a small, public RPM.
# Example: A minimal RPM might not have all headers for 'rpm.headers.keys()'
# but a real one will.
# Create a dummy RPM file for demonstration if you don't have one
# This is a highly simplified placeholder and may not be fully functional
# for all rpmfile operations, but demonstrates the API.
dummy_rpm_path = 'dummy.rpm'
with open(dummy_rpm_path, 'wb') as f:
# A very minimal (likely invalid) RPM header lead for rpmfile to attempt parsing
# Real RPMs are significantly more complex.
f.write(b'\xed\xab\xee\xdb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')
try:
with rpmfile.open(dummy_rpm_path) as rpm:
print(f"RPM Name: {rpm.headers.get('name', 'N/A')}")
print(f"RPM Version: {rpm.headers.get('version', 'N/A')}")
print(f"RPM Release: {rpm.headers.get('release', 'N/A')}")
# List members in the archive
print("\nArchive Members:")
members = rpm.getmembers()
if members:
for member in members:
print(f" - {member.name}")
else:
print(" (No members found or could not parse)")
# Example of extracting a file (will fail for dummy.rpm as no actual files)
# if './usr/bin/script' in [m.name for m in members]:
# fd = rpm.extractfile('./usr/bin/script')
# print(f"\nContent of ./usr/bin/script:\n{fd.read().decode()}")
except rpmfile.BadRpmfile as e:
print(f"Error opening RPM file: {e}. The dummy.rpm is likely too incomplete for full parsing.")
finally:
# Clean up the dummy file
if os.path.exists(dummy_rpm_path):
os.remove(dummy_rpm_path)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'rpmfile'
The `rpmfile` package is not installed in the current Python environment.
FileNotFoundError: [Errno 2] No such file or directory: 'path/to/non_existent.rpm'
The specified RPM file path does not exist or is inaccessible.
fixEnsure the RPM file exists at the given path and the program has read permissions.
ValueError: Not an RPM file (bad magic)
The file provided to `rpmfile.open()` does not begin with the expected RPM magic number, indicating it's not a valid RPM package.
fixVerify that the file is indeed a legitimate RPM package.
ValueError: Header is malformed
The RPM file's internal header structure is corrupted or incorrectly formatted, preventing `rpmfile` from parsing its metadata.
fixUse a known good RPM file; if the file is genuinely corrupted, it might be unrecoverable.
PermissionError: [Errno 13] Permission denied: '/path/to/unwritable_directory'
The Python process lacks the necessary write permissions for the specified directory where files are being extracted.
fixEnsure the user running the script has write permissions to the target extraction directory.
Upgrade
Version history
2.2.1latest on PyPI · released May 6, 2026
Audit
Dependencies
zstandardoptionalRequired for reading RPM files compressed with Zstandard. Requires Python >= 3.5.