This small Python module provides utilities for parsing Pip `requirements.txt` files and individual requirement strings. It extracts package names, versions, operators, VCS information, and environment markers, making it easier to programmatically inspect and manipulate dependency specifications. The library is actively maintained, with version 0.13.0 recently released, and typically sees several releases per year to address bug fixes and add new parsing features.
pip install requirements-parserVerified import paths — ran on the pinned version, not inferred.
Parse a requirement string or an entire `requirements.txt` file content into `Requirement` objects, then access their properties.
Upgrade to Python 3.8 or newer, or pin `requirements-parser<0.8.0` if unable to upgrade Python.
Review any code that interacts deeply with the parsed `Requirement` object's internals or relies on specific `pkg_resources` behaviors. Adapt to `packaging`-based behaviors if necessary.
Upgrade to version 0.10.2 or higher to ensure correct parsing of editable installs and VCS requirements with complex names or extras.
Always use `req.uri` instead of `req.url` when accessing URL-like components from a parsed requirement object returned by `requirements-parser`.
Install the package using pip: `pip install requirements-parser`
Change the import statement from `import requirements-parser` to `import requirements_parser`.
Always check if an optional attribute is not `None` before attempting to access its methods, e.g., `if req.version: print(req.version.startswith('1'))`.