{"id":15070081,"url":"https://github.com/bkircher/python-rpm-spec","last_synced_at":"2025-10-08T18:22:15.203Z","repository":{"id":43642988,"uuid":"77776730","full_name":"bkircher/python-rpm-spec","owner":"bkircher","description":"Python module for parsing RPM spec files","archived":false,"fork":false,"pushed_at":"2024-10-14T15:48:40.000Z","size":220,"stargazers_count":40,"open_issues_count":7,"forks_count":23,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-10-20T09:00:56.795Z","etag":null,"topics":["parser","python-3","rpm","spec-file"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bkircher.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-01T11:47:33.000Z","updated_at":"2024-10-12T08:17:43.000Z","dependencies_parsed_at":"2024-10-23T10:34:30.467Z","dependency_job_id":"ce73d694-ca42-4707-8ae5-fd2a21675516","html_url":"https://github.com/bkircher/python-rpm-spec","commit_stats":{"total_commits":285,"total_committers":22,"mean_commits":"12.954545454545455","dds":"0.38245614035087716","last_synced_commit":"9d1049a4011a650d5700c65acf1a5cd6d7863a91"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkircher%2Fpython-rpm-spec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkircher%2Fpython-rpm-spec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkircher%2Fpython-rpm-spec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkircher%2Fpython-rpm-spec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bkircher","download_url":"https://codeload.github.com/bkircher/python-rpm-spec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247174457,"owners_count":20896078,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["parser","python-3","rpm","spec-file"],"created_at":"2024-09-25T01:46:58.357Z","updated_at":"2025-10-08T18:22:15.123Z","avatar_url":"https://github.com/bkircher.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-rpm-spec\n\n[![pytest status](https://github.com/bkircher/python-rpm-spec/actions/workflows/test.yml/badge.svg)](https://github.com/bkircher/python-rpm-spec/actions/workflows/test.yml)\n[![PyPI version](https://badge.fury.io/py/python-rpm-spec.svg)](https://badge.fury.io/py/python-rpm-spec)\n\npython-rpm-spec is a Python-only library for parsing RPM spec files.\n\n_tl;dr_ If you want to quickly parse a spec file on the command line you might\nwant to give `rpmspec --parse` a try.\n\n```sh\nrpmspec --parse file.spec | awk '/Source/ {print $2}'\n```\n\nIf you write Python, have no `/usr/bin/rpm` around, or want to do something\nslightly more complicated, try using this Python library.\n\nRPMs are build from a package's sources along with a spec file. The spec file\ncontrols how the RPM is built. This library allows you to parse spec files and\ngives you simple access to various bits of information that is contained in the\nspec file.\n\n## Features\n\n- No extra dependencies other than Python 3.\n- Available on all platforms, parse spec files on Windows.\n- Read-only (for manipulating spec files see [Alternatives](#alternatives)\n  below).\n\n## Supported Python versions\n\nAll [current Python branches](https://devguide.python.org/versions/#versions)\nare supported.\n\n| Python Version | Supported Until |\n| :------------- | --------------: |\n| 3.13           |         2029-10 |\n| 3.12           |         2028-10 |\n| 3.11           |         2027-10 |\n| 3.10           |         2026-10 |\n| 3.9            |         2025-10 |\n\n## Install\n\npython-rpm-spec is [hosted](https://pypi.org/project/python-rpm-spec/) on PyPI -\nthe Python Package Index. All you need to do is\n\n```sh\npip install python-rpm-spec\n```\n\nin your virtual environment.\n\n## Examples\n\nThe libraries main API objects are the `Spec` object, representing an entire\nspec file and the `replace_macros` function which is used to expand macro's into\nabsolute string values.\n\nThis is how you access a spec file's various definitions:\n\n```python\nfrom pyrpm.spec import Spec, replace_macros\n\nspec = Spec.from_file('llvm.spec')\nprint(spec.version)  # 3.8.0\nprint(spec.sources[0])  # http://llvm.org/releases/%{version}/%{name}-%{version}.src.tar.xz\nprint(replace_macros(spec.sources[0], spec))  # http://llvm.org/releases/3.8.0/llvm-3.8.0.src.tar.xz\n\nfor package in spec.packages:\n    print(f'{package.name}: {package.summary if hasattr(package, \"summary\") else spec.summary}')\n\n    # llvm: The Low Level Virtual Machine\n    # llvm-devel: Libraries and header files for LLVM\n    # llvm-doc: Documentation for LLVM\n    # llvm-libs: LLVM shared libraries\n    # llvm-static: LLVM static libraries\n```\n\nExample showing how to retrieve named source or patch files from a spec:\n\n```python\nfrom pyrpm.spec import Spec\n\nspec = Spec.from_file('llvm.spec')\n\n# Access sources and patches via name\nfor k, v in spec.sources_dict.items():\n    print(f'{k} → {v}')\n\n# Source0 → http://llvm.org/releases/%{version}/%{name}-%{version}.src.tar.xz\n# Source100 → llvm-config.h\n\n# Or as a list with indices and so on\nfor source in spec.sources:\n    print(source)\n\n# http://llvm.org/releases/%{version}/%{name}-%{version}.src.tar.xz\n# llvm-config.h\n```\n\nExample showing how to get versioned `BuildRequires:` and `Requires:` out of a\nspec file:\n\n```python\nfrom pyrpm.spec import Spec\n\nspec = Spec.from_file('attica-qt5.spec')\n\n# Access sources and patches via name\nfor br in spec.build_requires:\n    print(f'{br.name} {br.operator} {br.version}' if br.version else f'{br.name}')\n\n# cmake \u003e= 3.0\n# extra-cmake-modules \u003e= %{_tar_path}\n# fdupes\n# kf5-filesystem\n# pkg-config\n# cmake(Qt5Core) \u003e= 5.6.0\n# cmake(Qt5Network) \u003e= 5.6.0\n```\n\nIf you want that the library\n[create warnings](https://docs.python.org/3/library/warnings.html) during\nparsing, for example on unknown macros, set `warnings_enabled` to `True`:\n\n```python\nimport pyrpm.spec\n\npyrpm.spec.warnings_enabled = True\n# …\n```\n\n## Dependencies\n\nNo extra dependencies are required except for Python 3.8 or newer.\n\n## Current status\n\nThis library is an ambitious Python script that became a library. It is not\ncomplete and it does not fit every use case.\n\n- It is probably very slow and it relies on regular expressions for parsing.\n- It does not parse everything in a spec file, only the pieces myself and others\n  needed so far.\n\nSo there is probably still plenty of stuff missing (i.e. support for\n[`%include`](https://github.com/bkircher/python-rpm-spec/issues/51)). However,\nit should not be too complicated to add support for the missing pieces.\n\nAlso note that there is a\n[GitHub workflow](https://github.com/bkircher/python-rpm-spec/actions/workflows/fedora-sources.yml)\nthat runs the parser on Fedora's spec files.\n\n## Alternatives\n\nHere is a list of alternatives to this library:\n\n- [packit/specfile](https://github.com/packit/specfile) - Allows parsing and,\n  different to python-rpm-spec, the manipulation of spec files. Part of packit.\n  Actively developed as of March 2023.\n- If you are on a Linux system that has the RPM package manager installed,\n  consider using system tools like\n  - `rpmspec(8)` from rpm-build package. Example: `rpmspec --parse foo.spec`\n    will parse a spec file to stdout, expanding all the macros installed on the\n    system. Still relies on `$HOME/rpmbuild` to work.\n  - `rpmdev-spectool(1)` from rpmdevtools package. Example:\n    `spectool --get-files foo.spec` will download all sources and patches from a\n    spec file.\n\n  The parsers of those system tools are probably more up to date and less buggy\n  than this library.\n\n## Development\n\nIf you want to hack on this library you could start with following recipe:\n\n```sh\ngit clone https://github.com/bkircher/python-rpm-spec.git  # Clone the repo\ncd python-rpm-spec  # Change into the source directory\npython3 -m venv .venv  # Create a virtual environment\nsource .venv/bin/activate  # Activate it\npip install -r requirements.txt  # Install dependencies for development\npytest  # Execute all tests\nmypy . # Run the type checker\n```\n\nThat's it. Make sure to check out the\n[issue tracker](https://github.com/bkircher/python-rpm-spec/issues) for things\nto work on or open a\n[new issue](https://github.com/bkircher/python-rpm-spec/issues/new/choose) to\nlet others know what you are working on.\n\n## Further references\n\n- [RPM project documentation](https://rpm.org/documentation.html) with a couple\n  of links to books or Fedora project documentation.\n- Take a look at the excellent\n  [RPM Packaging Guide](https://rpm-guide.readthedocs.io/en/latest/index.html),\n  especially the section\n  [What is a SPEC File?](https://rpm-guide.readthedocs.io/en/latest/rpm-guide.html#what-is-a-spec-file)\n\nHappy hacking!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkircher%2Fpython-rpm-spec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbkircher%2Fpython-rpm-spec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkircher%2Fpython-rpm-spec/lists"}