Registry / devops / dparse

dparse

JSON →
library0.6.4pypypi✓ verified 25d ago

dparse is a Python library designed to parse various Python dependency file formats such as `requirements.txt`, `Pipfile`, `Pipfile.lock`, `poetry.lock`, `setup.py`, `setup.cfg`, and `pyproject.toml`. It extracts dependency information, including names, versions, and extras, into a structured format. The current version is 0.6.4, with releases occurring on an irregular but active basis.

pip install dparse
INSTALL
IMPORT
SIG · DPARSE
D
dparse
devopspythonv0.6.4
Install
1.6s avg
Import
166ms
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.6.4 · 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.172s · 18.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.160s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

parse
from dparse import parse
The `parse` function is the primary entry point for parsing dependency strings or file-like objects.

This quickstart demonstrates how to use `dparse.parse` to extract dependencies from a string representing a `requirements.txt` file and a `Pipfile.lock`. The `filename` argument helps `dparse` identify the correct parsing strategy. The output shows the name and version specifier for each detected dependency.

from dparse import parse requirements_content = """ flask>=2.0.0 requests==2.28.1; python_version < "3.9" django """ dependencies = parse(requirements_content, filename='requirements.txt') print(f"Parsed {len(dependencies.dependencies)} dependencies:") for dep in dependencies.dependencies: print(f"- {dep.name}: {dep.specifier} (line {dep.line_number})") # Example for a specific file type (e.g., Pipfile.lock) pipfile_lock_content = """ {'_meta': {'hash': {'sha256': '...'}}, 'default': { 'requests': {'hashes': [...], 'version': '==2.28.1'}} } """ dep_from_lock = parse(pipfile_lock_content, filename='Pipfile.lock') print(f"\nParsed {len(dep_from_lock.dependencies)} from Pipfile.lock:") for dep in dep_from_lock.dependencies: print(f"- {dep.name}: {dep.specifier}")
Debug
Known issues
breakingPython 3.6 support was dropped in `dparse` version 0.6.0. Users on Python 3.6 or older must upgrade their Python environment to at least 3.7 to use versions 0.6.0 and later.
fix
Upgrade your Python interpreter to version 3.7 or newer, or pin `dparse<0.6.0` if unable to upgrade Python.
affects: >=0.6.0
breakingThe `dparse.pyup_parser` module was removed in version 0.4.0. Direct imports from this module will fail.
fix
Migrate to using the main `dparse.parse` function, which now encapsulates the parsing logic for various file types and is the recommended entry point.
affects: >=0.4.0
gotcha`dparse` provides heuristic parsing for `setup.py` files. Due to the dynamic nature of `setup.py`, complex or non-standard setups might not be fully or accurately parsed.
fix
For projects relying heavily on `setup.py` for dependency definition, consider migrating to `pyproject.toml` or `setup.cfg` for more reliable and static dependency declaration. Always verify the parsed output for `setup.py` files.
affects: All versions
gotcha`dparse` is solely a *parser* of dependency files. It does not resolve dependencies, install packages, or interact with package indexes. Its output is a structured representation of the dependencies as declared in the input file.
fix
Do not expect `dparse` to perform dependency resolution or installation. Use tools like `pip`, `Poetry`, or `Pipenv` for those tasks after parsing.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'dparse'
The 'dparse' library has not been installed in your current Python environment.
fix
Install the package using pip: `pip install dparse`
AttributeError: 'Parser' object has no attribute 'parse_file'
The `dparse.dependencies.Parser` class does not have a method named `parse_file`. Instead, parsing methods like `parse_requirements` or the generic `parse` method expect the file's content as a string.
fix
Read the file content into a string and then pass it to the appropriate parsing method:
```python
from dparse.dependencies import Parser

parser = Parser()
with open("requirements.txt", "r") as f:
    content = f.read()
dependencies = parser.parse_requirements(content)
# Or, for the generic parse method:
# dependencies = parser.parse(content)
```
ImportError: cannot import name 'parse' from 'dparse.dependencies'
The `parse` function is a method of the `Parser` class, not a directly importable function from the `dparse.dependencies` module.
fix
Import the `Parser` class and instantiate it to call its `parse` method:
```python
from dparse.dependencies import Parser

parser = Parser()
dependencies = parser.parse("numpy==1.20.0")
```
TypeError: expected string or bytes-like object
The parsing methods in `dparse` (e.g., `parse_requirements`, `parse`) expect the *content* of the dependency file as a string. This error occurs when a non-string object, such as an open file handle, is passed directly.
fix
Ensure you read the content of the file into a string before passing it to the parser:
```python
from dparse.dependencies import Parser

parser = Parser()
with open("requirements.txt", "r") as f:
    content = f.read()
dependencies = parser.parse_requirements(content)
```
Upgrade
Version history
0.6.4latest on PyPI · released Nov 8, 2024
Audit
Dependencies
packagingrequiredUsed for parsing and comparing version specifiers.
setuptoolsrequiredUsed internally for parsing setup.py/setup.cfg files.
Agent activity
23 hits · last 30 days
node
18
OpenAI (training)
1
Resources
dparse — pip install dparse · libregistry