{"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":"en","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":[{"note":"Directly importing from `pip._internal` is strongly discouraged by pip's developers as its APIs are unstable and subject to change without notice. `pip-requirements-parser` provides a stable wrapper around this complex parsing logic.","wrong":"from pip._internal.req import parse_requirements","symbol":"parse","correct":"import requirements\nfor req in requirements.parse(req_string):"}],"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"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}