{"id":5464,"library":"rpmfile","title":"rpmfile","description":"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.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/srossross/rpmfile","tags":["rpm","archive","package","parsing","metadata"],"install":[{"cmd":"pip install rpmfile","lang":"bash","label":"Basic Install"},{"cmd":"pip install 'rpmfile[zstd]' # Or: pip install rpmfile zstandard","lang":"bash","label":"Install with Zstandard Support"}],"dependencies":[{"reason":"Required for reading RPM files compressed with Zstandard. Requires Python >= 3.5.","package":"zstandard","optional":true}],"imports":[{"symbol":"rpmfile","correct":"import rpmfile"},{"symbol":"RPMFile","correct":"from rpmfile import RPMFile"}],"quickstart":{"code":"import rpmfile\nimport os\n\n# NOTE: Replace 'path/to/your/file.rpm' with an actual RPM file path.\n# For a runnable example, you'd typically download a small, public RPM.\n# Example: A minimal RPM might not have all headers for 'rpm.headers.keys()'\n# but a real one will.\n\n# Create a dummy RPM file for demonstration if you don't have one\n# This is a highly simplified placeholder and may not be fully functional\n# for all rpmfile operations, but demonstrates the API.\ndummy_rpm_path = 'dummy.rpm'\nwith open(dummy_rpm_path, 'wb') as f:\n    # A very minimal (likely invalid) RPM header lead for rpmfile to attempt parsing\n    # Real RPMs are significantly more complex.\n    f.write(b'\\xed\\xab\\xee\\xdb\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00' \\\n            b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00' \\\n            b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00' \\\n            b'\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00')\n\ntry:\n    with rpmfile.open(dummy_rpm_path) as rpm:\n        print(f\"RPM Name: {rpm.headers.get('name', 'N/A')}\")\n        print(f\"RPM Version: {rpm.headers.get('version', 'N/A')}\")\n        print(f\"RPM Release: {rpm.headers.get('release', 'N/A')}\")\n\n        # List members in the archive\n        print(\"\\nArchive Members:\")\n        members = rpm.getmembers()\n        if members:\n            for member in members:\n                print(f\"  - {member.name}\")\n        else:\n            print(\"  (No members found or could not parse)\")\n\n        # Example of extracting a file (will fail for dummy.rpm as no actual files)\n        # if './usr/bin/script' in [m.name for m in members]:\n        #     fd = rpm.extractfile('./usr/bin/script')\n        #     print(f\"\\nContent of ./usr/bin/script:\\n{fd.read().decode()}\")\nexcept rpmfile.BadRpmfile as e:\n    print(f\"Error opening RPM file: {e}. The dummy.rpm is likely too incomplete for full parsing.\")\nfinally:\n    # Clean up the dummy file\n    if os.path.exists(dummy_rpm_path):\n        os.remove(dummy_rpm_path)\n","lang":"python","description":"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."},"warnings":[{"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.","message":"Version 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.","severity":"breaking","affected_versions":"< 2.1.0"},{"fix":"Upgrade to `rpmfile` 2.0.0 or newer to correctly parse and access localized RPM headers.","message":"Prior 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.","severity":"gotcha","affected_versions":"< 2.0.0"},{"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.","message":"In 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.","severity":"gotcha","affected_versions":"< 1.0.8"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}