Registry / serialization / rpmfile

rpmfile

JSON →
library2.2.1pypypi✓ verified 24d ago

The `rpmfile` library (current version 2.1.0, released July 24, 2024) provides tools for inspecting RPM archive files in Python. It is designed to be similar to Python's built-in `tarfile` module, offering an interface to read and extract contents, as well as inspect metadata (headers) of RPM packages. The project maintains an active development status with regular updates addressing parsing correctness and adding features.

pip install rpmfile
INSTALL
IMPORT
SIG · RPMFILE
R
rpmfile
serializationpythonv2.2.1
Install
1.5s avg
Import
46ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.048s · 17.9MB
glibc
py 3.103.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
import rpmfile
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)
Debug
Known issues
breakingVersion 2.1.0 fixed incorrect parsing of the first headers block (signature headers) and ensures integer header data values are unpacked as unsigned. This means that applications relying on potentially incorrect signed integer values or misparsed signature data from earlier versions may see changes in behavior or data interpretation when upgrading.
fix
Upgrade to `rpmfile` 2.1.0 or newer and re-evaluate any code that directly processes RPM header integer values or signature data to ensure it correctly handles the updated parsing behavior.
affects: < 2.1.0
gotchaPrior to version 2.0.0, `rpmfile` could fail to load localized RPM headers, potentially leading to incomplete or incorrect metadata extraction for packages with internationalized summaries or descriptions.
fix
Upgrade to `rpmfile` 2.0.0 or newer to correctly parse and access localized RPM headers.
affects: < 2.0.0
gotchaIn versions prior to 1.0.8, the library relied on `nlinks` to identify directories within a CPIO archive, which could lead to incorrect identification in certain cases. Version 1.0.8 switched to using mode bits for more accurate directory identification.
fix
Upgrade to `rpmfile` 1.0.8 or newer to ensure correct identification of directories within RPM archives, particularly if performing operations based on file types.
affects: < 1.0.8
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'rpmfile'
The `rpmfile` package is not installed in the current Python environment.
fix
pip install rpmfile
FileNotFoundError: [Errno 2] No such file or directory: 'path/to/non_existent.rpm'
The specified RPM file path does not exist or is inaccessible.
fix
Ensure 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.
fix
Verify 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.
fix
Use 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.
fix
Ensure 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.
Agent activity
14 hits · last 30 days
node
8
OpenAI (training)
1
Resources
rpmfile — pip install rpmfile · libregistry