Registry / data / requirements-parser

requirements-parser

JSON →
library0.13.1pypypi✓ verified 27d ago

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.

pip install requirements-parser
INSTALL
IMPORT
SIG · REQUIREMENTS-PARSE
R
requirements-parser
datapythonv0.13.1
Install
1.7s avg
Import
136ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.13.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.140s · 18.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.132s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
from requirements.parser import parse

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}")
Debug
Known issues
breakingSupport 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`.
fix
Upgrade to Python 3.8 or newer, or pin `requirements-parser<0.8.0` if unable to upgrade Python.
affects: >=0.8.0
gotchaVersion 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.
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.
affects: >=0.11.0
gotchaParsing 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.
fix
Upgrade to version 0.10.2 or higher to ensure correct parsing of editable installs and VCS requirements with complex names or extras.
affects: <0.10.2
gotchaThe `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`.
fix
Always use `req.uri` instead of `req.url` when accessing URL-like components from a parsed requirement object returned by `requirements-parser`.
affects: >=0.1.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'requirements_parser'
The `requirements-parser` package is either not installed in your environment or is not installed in the Python environment currently being used.
fix
Install the package using pip: `pip install requirements-parser`
SyntaxError: invalid syntax
Python module names in `import` statements cannot contain hyphens; the installed package `requirements-parser` must be imported using an underscore.
fix
Change the import statement from `import requirements-parser` to `import requirements_parser`.
AttributeError: 'NoneType' object has no attribute 'startswith'
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.
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'))`.
Upgrade
Version history
0.13.1latest on PyPI · released Jun 18, 2026
Audit
Dependencies
packagingrequiredUsed for robust parsing and normalization of package versions and specifiers, replacing the deprecated `pkg_resources` module.
Agent activity
8 hits · last 30 days
node
6
OpenAI (training)
1
Resources
requirements-parser — pip install requirements-parser · libregistry