A lightweight Python utility that scans .py files to detect all import statements, identifies the corresponding PyPI packages, and determines their installed version numbers. This tool automatically generates an accurate and minimal requirements.txt (or dependency list), making it ideal for packaging, deployment, and environment reproduction.
Project description
minireqs
A lightweight Python utility that automatically generates requirements.txt files by scanning Python files, detecting import statements, and identifying the corresponding PyPI packages with their installed versions.
Purpose
Automatically extract minimal dependency requirements from your Python codebase, making it ideal for packaging, deployment, and environment reproduction.
Notes: (1) The package must be installed in the same Python environment as the project so it can detect the packages and versions actually in use. (2) Only detection of packages installed via pip has been tested so far. (3) Even if all packages are installed via pip, there is still a chance that some required packages won’t be detected if they are never explicitly imported in your scripts. Once the generated requirements are installed in a clean/fresh environment, test again—or build and run your Docker image—to check for any missing dependencies.
Main Functions
extract_pip_requirement(script_path, req_path, QA=False)
Main function that extracts pip requirements from a Python file or directory.
- Parameters:
script_path: Path to a Python file or directory (default:'main.py')req_path: Output path for requirements file (default:'req_main.txt')QA: IfTrue, prints the results DataFrame
- Returns: DataFrame with import names and their corresponding pip package requirements
get_imports(script_path)
Extracts all import statements from a Python file using AST parsing.
- Parameters:
script_path- Path to a Python file - Returns: List of import names found in the file
find_pip_pkg(import_name)
Finds the corresponding PyPI package name and version for an import statement.
- Parameters:
import_name- The import name (e.g.,'pandas','numpy') - Returns: Tuple of
(package_name, version)or(None, None)if not found
Utility Functions
find_py_files(script_path): Recursively finds all.pyfiles in a directory or returns a single file pathsafe_import(name): Safely imports a module by progressively stripping attributes
Installation
pip install minireqs
or
pip install minireqs[Numpy1]
Usage
from minireqs.pip_package_extract import extract_pip_requirement, generate_full_requirements
# Extract requirements from a file or directory
df = extract_pip_requirement('my_script.py', 'requirements.txt')
# Generate a full universal requirements file from a minimum requirements file
generate_full_requirements(min_req_file, full_universal_req_file)
Requirements
- Python >= 3.10
- Default option: (numpy >= 2.0.0, pandas >= 2.2.2, uv)
- [Numpy1] option: (1.21.0 <= numpy < 2.0.0, 2.0.0 <= pandas < 2.2.2, uv)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file minireqs-0.5.0.tar.gz.
File metadata
- Download URL: minireqs-0.5.0.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f42e007dd53240886f1a25464d6931ec1f2a9b6cde7dfb18f1ebfc38663594e
|
|
| MD5 |
449b1598b50373b4d6693acdc72553b8
|
|
| BLAKE2b-256 |
bdda847e984c6ffe108c4300c287d392d3dacef40d34683e4d73dd55a71960a7
|
Provenance
The following attestation bundles were made for minireqs-0.5.0.tar.gz:
Publisher:
publish.yml on drmathesis/minireqs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
minireqs-0.5.0.tar.gz -
Subject digest:
9f42e007dd53240886f1a25464d6931ec1f2a9b6cde7dfb18f1ebfc38663594e - Sigstore transparency entry: 732123204
- Sigstore integration time:
-
Permalink:
drmathesis/minireqs@1b03afc1be5ac694311323c2c8a8b2eb4f728187 -
Branch / Tag:
refs/tags/ver-0.5.0 - Owner: https://github.com/drmathesis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b03afc1be5ac694311323c2c8a8b2eb4f728187 -
Trigger Event:
release
-
Statement type:
File details
Details for the file minireqs-0.5.0-py3-none-any.whl.
File metadata
- Download URL: minireqs-0.5.0-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6e89c8fd2f0e8c31455df210dfc8413740367c50e91d2e7eee92a3c1f0d3143
|
|
| MD5 |
66bc64bf04ec028e7a3aa18a32396f4c
|
|
| BLAKE2b-256 |
14ebb08915c20737d99e60b5b4fe6197c5063c26ef57bf1efdab85f205ffe94e
|
Provenance
The following attestation bundles were made for minireqs-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on drmathesis/minireqs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
minireqs-0.5.0-py3-none-any.whl -
Subject digest:
a6e89c8fd2f0e8c31455df210dfc8413740367c50e91d2e7eee92a3c1f0d3143 - Sigstore transparency entry: 732123207
- Sigstore integration time:
-
Permalink:
drmathesis/minireqs@1b03afc1be5ac694311323c2c8a8b2eb4f728187 -
Branch / Tag:
refs/tags/ver-0.5.0 - Owner: https://github.com/drmathesis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1b03afc1be5ac694311323c2c8a8b2eb4f728187 -
Trigger Event:
release
-
Statement type: