{"id":1266,"library":"pip-requirements-parser","title":"pip-requirements-parser","description":"pip-requirements-parser is a Python library designed for robustly parsing `pip` requirement files. It distinguishes itself by leveraging `pip`'s own internal parsing logic, ensuring high accuracy in handling the diverse and often complex `pip` requirement format. The library provides a stable, offline API for parsing, making it suitable for environments where network access is restricted or where precise `pip`-compatible parsing is critical. It is currently at version 32.0.1 and aims for a stable API for its users, despite the inherent complexities of `pip`'s internal requirement file format.","status":"active","version":"32.0.1","language":"python","source_language":"en","source_url":"https://github.com/nexB/pip-requirements-parser","tags":["pip","requirements","parser","packaging","dependency"],"install":[{"cmd":"pip install pip-requirements-parser","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Used for parsing and manipulating package version specifiers, as part of its internal logic derived from pip.","package":"packaging"}],"imports":[{"wrong":"import requirements; requirements.parse","symbol":"parse","correct":"from pip_requirements_parser import parse"},{"symbol":"InvalidVersion","correct":"from packaging_legacy_version import InvalidVersion"},{"symbol":"LegacyVersion","correct":"from packaging_legacy_version import LegacyVersion"}],"quickstart":{"code":"import requirements\n\nreq_string = \"\"\"\ndjango==3.2.1\nrequests>=2.25.1,<3.0.0\n-e git+https://github.com/my/project.git#egg=myproject\n\"\"\"\n\n# Parse a string of requirements\nfor req in requirements.parse(req_string):\n    print(f\"Name: {req.name}, Specs: {req.specs}, Vcs: {req.vcs}, Url: {req.url}\")\n\n# You can also parse from a file-like object\n# with open('requirements.txt', 'r') as f:\n#     for req in requirements.parse(f):\n#         print(f\"Name: {req.name}, Specs: {req.specs}\")","lang":"python","description":"This quickstart demonstrates how to parse a string containing pip-style requirements using `requirements.parse()`. Each parsed requirement object provides attributes like `name`, `specs` (version specifiers), `vcs` (Version Control System information), and `url` for detailed analysis. The library also supports parsing directly from file-like objects."},"warnings":[{"fix":"Rely on `pip-requirements-parser`'s documented API. If issues arise with new `pip` requirement syntaxes, ensure you are using the latest version of `pip-requirements-parser` as it tracks `pip`'s internal changes.","message":"The `pip` requirements file format is tightly coupled with `pip`'s internal implementation details and command-line options, making it notoriously difficult to parse correctly. While `pip-requirements-parser` aims to provide a stable API by incorporating `pip`'s own logic, users should be aware that the underlying `requirements.txt` format is not a stable public API and its full syntax can evolve with `pip` releases.","severity":"gotcha","affected_versions":"All versions"},{"fix":"For package distribution, define dependencies in `pyproject.toml` (PEP 508). Use `pip-requirements-parser` only when you explicitly need to read and interpret the `requirements.txt` format itself, for example, in tools that analyze application environments.","message":"It is generally discouraged to parse `requirements.txt` files directly to populate `install_requires` in `setup.py` or `pyproject.toml` for package distribution. Packaging metadata (e.g., in `pyproject.toml`'s `[project]` section) should use PEP 508 compliant specifiers for abstract dependencies, while `requirements.txt` is typically for concrete/pinned dependencies of applications.","severity":"gotcha","affected_versions":"All versions"},{"fix":"This is generally a feature for isolation and speed. If you require resolution of network-based requirements (e.g., installing packages from custom URLs or VCS), you will need to use `pip` directly or another tool that handles network operations.","message":"Unlike `pip` itself, which might perform network requests during its operations (e.g., resolving VCS requirements or fetching metadata), `pip-requirements-parser` is designed to work entirely offline. It parses the syntax without making external network calls.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure `pip-requirements-parser` is installed in your Python environment by running `pip install pip-requirements-parser`. If you are using a virtual environment, make sure it is activated before installation.","message":"The `ModuleNotFoundError: No module named 'requirements'` indicates that the `pip-requirements-parser` library (which is typically imported as `requirements`) was not found in the Python environment. This means the library was not installed or its installation path was not accessible.","severity":"breaking","affected_versions":"All versions"},{"fix":"Ensure `pip-requirements-parser` is installed in your Python environment. You can typically install it using `pip install pip-requirements-parser`.","message":"The library `pip-requirements-parser` must be installed to be imported successfully. Encountering `ModuleNotFoundError: No module named 'requirements'` indicates that the package is either not installed or not accessible in the current Python environment.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'32.0.1':76 'access':60 'accuraci':33 'aim':78 'api':50,82 'compat':67 'complex':40,89 'critic':70 'current':73 'depend':101 'design':13 'despit':86 'distinguish':21 'divers':37 'ensur':31 'environ':57 'file':19,95 'format':43,96 'handl':35 'high':32 'inher':88 'intern':28,93 'leverag':24 'librari':12,45 'logic':30 'make':53 'network':59 'offlin':49 'often':39 'packag':100 'pars':16,29,52,68 'parser':4,8,99 'pip':2,6,17,25,41,66,91,97 'pip-requirements-pars':1,5 'precis':65 'provid':46 'python':11 'requir':3,7,18,42,94,98 'restrict':62 'robust':15 'stabl':48,81 'suitabl':55 'user':85 'version':75","created_at":"2026-04-06T16:57:09.676807+00:00","updated_at":"2026-04-16T18:02:06.688624+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":0,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"32.0.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/nexB/pip-requirements-parser","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pip-requirements-parser/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-30","last_verified":"2026-08-27","next_check":"2026-07-30","install_tag":"stale"}}