Requirements Parser

0.13.0 · active · verified Wed Apr 08

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.

Warnings

Install

Imports

Quickstart

Parse a requirement string or an entire `requirements.txt` file content into `Requirement` objects, then access their properties.

from requirements.parser import parse

requirement_string = "requests[security]==2.31.0; python_version<\"3.12\""

for req in parse(requirement_string):
    print(f"Name: {req.name}")
    print(f"Specs: {req.specs}")
    print(f"Extras: {req.extras}")
    print(f"URL: {req.url}")
    print(f"VCS: {req.vcs}")
    print(f"Hash: {req.hash}")
    print(f"Environment Marker: {req.marker}")

view raw JSON →