Requirements Detector
requirements-detector is a simple Python tool designed to find and list the dependencies of a Python project. It analyzes various common project files to ascertain required libraries and their versions. The current version is 1.5.0, and it appears to be under active development with periodic updates.
Warnings
- gotcha The detector prioritizes parsing order: `setup.py` first, then `pyproject.toml` (specifically `tool.poetry.dependencies`), followed by `requirements.txt`, `requirements.pip`, and other `*.txt`/`*.pip` files in a 'requirements' folder or the root. Users should be aware of this order, as requirements found earlier will prevent later files from being parsed.
- gotcha The tool is described as 'simple' and primarily focuses on finding and listing requirements. It might not robustly handle highly complex, unconventional project structures, or advanced dependency resolution scenarios beyond its defined parsing mechanisms. It does not perform full dependency resolution or conflict detection.
- gotcha When used via the command-line interface (`detect-requirements`), the output is plaintext, formatted to resemble a standard `pip requirements` file. If you need structured data (e.g., for further programmatic processing), you must use the Python API, specifically the `find_requirements` function or other `from_*` functions, which return `DetectedRequirement` objects.
Install
-
pip install requirements-detector
Imports
- find_requirements
from requirements_detector import find_requirements
- from_requirements_txt
from requirements_detector import from_requirements_txt
- from_setup_py
from requirements_detector import from_setup_py
- from_pyproject_toml
from requirements_detector import from_pyproject_toml
Quickstart
import os
from requirements_detector import find_requirements
# Detect requirements in the current working directory
detected_reqs = find_requirements(os.getcwd())
for req in detected_reqs:
print(f"Detected: {req.name} {req.specifier}")
# Example for a specific requirements.txt file
# from requirements_detector import from_requirements_txt
# reqs_from_file = from_requirements_txt("/path/to/your/project/requirements.txt")
# for req in reqs_from_file:
# print(f"From file: {req.name} {req.specifier}")