{"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":"python","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"},{"fix":"Always use `req.uri` instead of `req.url` when accessing URL-like components from a parsed requirement object returned by `requirements-parser`.","message":"The `requirements-parser.Requirement` object exposes parsed URL-like components (such as for VCS or direct URL requirements) via the `uri` attribute, not `url`. Attempting to access `req.url` will result in an `AttributeError`.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'0.13.0':46 'activ':42 'add':61 'address':57 'bug':58 'depend':37,68 'easier':31 'environ':27 'extract':19 'featur':64 'file':13 'fix':59 'individu':15 'inform':25 'inspect':34 'librari':40 'maintain':43 'make':29 'manipul':36 'marker':28 'modul':6 'name':21 'new':62 'oper':23 'packag':20 'pars':10,63,65 'parser':2 'per':54 'pip':11,67 'programmat':33 'provid':7 'python':5 'recent':47 'releas':48,53 'requir':1,16 'requirements.txt':12,66 'see':51 'sever':52 'small':4 'specif':38 'string':17 'typic':50 'util':8 'vcs':24 'version':22,45 'year':55","created_at":"2026-04-08T16:04:41.449703+00:00","updated_at":"2026-04-16T20:57:38.400145+00:00","problems":[{"fix":"Install the package using pip: `pip install requirements-parser`","cause":"The `requirements-parser` package is either not installed in your environment or is not installed in the Python environment currently being used.","error":"ModuleNotFoundError: No module named 'requirements_parser'"},{"fix":"Change the import statement from `import requirements-parser` to `import requirements_parser`.","cause":"Python module names in `import` statements cannot contain hyphens; the installed package `requirements-parser` must be imported using an underscore.","error":"SyntaxError: invalid syntax"},{"fix":"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'))`.","cause":"You are attempting to call a method (like `startswith`) on an attribute (such as `version` or `specs`) of a `Requirement` object, but that attribute is `None` because the parsed requirement string did not specify a value for it.","error":"AttributeError: 'NoneType' object has no attribute 'startswith'"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.13.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/madpah/requirements-parser","docs":"https://requirements-parser.readthedocs.io/","changelog":null,"pypi":"https://pypi.org/project/requirements-parser/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":"verified"}}