{"id":1305,"library":"requirements-parser","title":"Requirements Parser","description":"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.","status":"active","version":"0.13.0","language":"en","source_language":"en","source_url":"https://github.com/madpah/requirements-parser","tags":["parsing","requirements.txt","pip","dependencies"],"install":[{"cmd":"pip install requirements-parser","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Used for robust parsing and normalization of package versions and specifiers, replacing the deprecated `pkg_resources` module.","package":"packaging","optional":false}],"imports":[{"symbol":"parse","correct":"from requirements.parser import parse"}],"quickstart":{"code":"from requirements.parser import parse\n\nrequirement_string = \"requests[security]==2.31.0; python_version<\\\"3.12\\\"\"\n\nfor req in parse(requirement_string):\n    print(f\"Name: {req.name}\")\n    print(f\"Specs: {req.specs}\")\n    print(f\"Extras: {req.extras}\")\n    print(f\"URL: {req.url}\")\n    print(f\"VCS: {req.vcs}\")\n    print(f\"Hash: {req.hash}\")\n    print(f\"Environment Marker: {req.marker}\")","lang":"python","description":"Parse a requirement string or an entire `requirements.txt` file content into `Requirement` objects, then access their properties."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer, or pin `requirements-parser<0.8.0` if unable to upgrade Python.","message":"Support for Python 3.7 was officially dropped in version 0.8.0. Users on Python 3.7 must remain on `requirements-parser<0.8.0`.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"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.","message":"Version 0.11.0 replaced the deprecated `pkg_resources` module with `packaging` for internal parsing logic. While generally an improvement, users who might have relied on specific internal behaviors or properties exposed by `pkg_resources` in earlier versions could encounter subtle changes in parsing outcomes or object structures. Ensure thorough testing after upgrading.","severity":"gotcha","affected_versions":">=0.11.0"},{"fix":"Upgrade to version 0.10.2 or higher to ensure correct parsing of editable installs and VCS requirements with complex names or extras.","message":"Parsing of editable installations (`-e .`) and VCS requirements with extras (`git+https://...#egg=package[extras]`) had fixes in versions 0.10.1 and 0.10.2 respectively. Older versions might incorrectly parse these common requirement types, leading to unexpected behavior or `ValueError` exceptions.","severity":"gotcha","affected_versions":"<0.10.2"}],"env_vars":null,"last_verified":"2026-04-08T00:00:00.000Z","next_check":"2026-07-07T00:00:00.000Z"}