pip-requirements-parser

32.0.1 · active · verified Mon Apr 06

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.

Warnings

Install

Imports

Quickstart

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.

import requirements

req_string = """
django==3.2.1
requests>=2.25.1,<3.0.0
-e git+https://github.com/my/project.git#egg=myproject
"""

# Parse a string of requirements
for req in requirements.parse(req_string):
    print(f"Name: {req.name}, Specs: {req.specs}, Vcs: {req.vcs}, Url: {req.url}")

# You can also parse from a file-like object
# with open('requirements.txt', 'r') as f:
#     for req in requirements.parse(f):
#         print(f"Name: {req.name}, Specs: {req.specs}")

view raw JSON →