Generate requirements.txt from your Python imports
Project description
reqsgen
Generate requirements.txt from your Python imports automatically.
Overview
reqsgen is a zero-config, offline-only Python tool that scans your project's .py files for external imports and generates a minimal, sorted requirements.txt. No network calls, no API keys, no extra configuration required.
Features
- 🔍 Automatic Import Discovery: Recursively scans Python files and extracts all imports
- 📚 Standard Library Filtering: Automatically excludes Python standard library modules
- 📝 Clean Output: Generates sorted, minimal requirements.txt files
- 🔒 Offline Operation: No network calls or external dependencies required
- ⚡ Zero Configuration: Works out of the box with sensible defaults
- 📌 Version Pinning: Optional version pinning for reproducible environments
Installation
pip install reqsgen
Usage
Command Line
Generate requirements.txt from current directory:
reqsgen
Scan a specific directory:
reqsgen /path/to/your/project
Specify output file:
reqsgen . -o my-requirements.txt
Pin package versions:
reqsgen . --pin
Python API
from reqsgen import find_imports, filter_stdlib, generate_requirements
# Find all imports in a project
imports = find_imports("/path/to/project")
# Filter out standard library modules
external_packages = filter_stdlib(imports)
# Generate requirements file
num_packages = generate_requirements(
path="/path/to/project",
output_file="requirements.txt",
pin_versions=True
)
How It Works
- Scan: Recursively walks through your project directory finding all
.pyfiles - Parse: Uses Python's
astmodule to safely parse each file and extract import statements - Filter: Removes standard library modules using a comprehensive built-in list
- Generate: Creates a sorted requirements.txt with only external packages
Command Line Options
usage: reqsgen [-h] [-o OUTPUT] [--pin] [--version] [path]
Generate requirements.txt from your Python imports
positional arguments:
path Path to scan for Python files (default: current directory)
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output file path (default: requirements.txt)
--pin Pin package versions (e.g., package==1.2.3)
--version show program's version number and exit
Examples
Basic Usage
$ reqsgen
Wrote 5 packages to requirements.txt
With Version Pinning
$ reqsgen --pin
Wrote 5 packages to requirements.txt
Generated requirements.txt:
flask==2.3.3
requests==2.31.0
numpy==1.24.3
pandas==2.0.3
click==8.1.7
Requirements
- Python 3.8+
- No external dependencies (uses only Python standard library)
License
MIT License - see LICENSE file for details.
Development
Running Tests
# Install development dependencies
pip install pytest
# Run the test suite
python -m pytest tests/ -v
# Run comprehensive integration tests
python test_real_project.py
python test_edge_cases.py
Building and Publishing
# Install build tools
pip install build twine
# Build the package
python -m build
# Check the distribution
python -m twine check dist/*
# Upload to PyPI (requires account and API token)
python -m twine upload dist/*
Changelog
v0.1.0 (2024-12-15)
- Initial release
- Basic import scanning and requirements generation
- Standard library filtering
- Version pinning support
- Command-line interface
- Python API
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
- Clone the repository
- Create a virtual environment:
python -m venv venv - Activate it:
source venv/bin/activate(Linux/Mac) orvenv\Scripts\activate(Windows) - Install in development mode:
pip install -e . - Install test dependencies:
pip install pytest - Run tests:
python -m pytest tests/ -v
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 reqsgen-0.1.0.tar.gz.
File metadata
- Download URL: reqsgen-0.1.0.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
65866c51442abfbc30c81c0c8e83d2c80cce2004928ef6e89d3eb574039db76c
|
|
| MD5 |
009aa87cef7356524573d65819f88cfa
|
|
| BLAKE2b-256 |
309f327692bfde7bd7b6231393a72102e826140641c77b5332328db8a1bb2cc9
|
File details
Details for the file reqsgen-0.1.0-py3-none-any.whl.
File metadata
- Download URL: reqsgen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aae8500e8d2363c3bdc5a0630887153d0b134c14774e6a56d76ff8437118b12b
|
|
| MD5 |
3364527b3aab2a5b3f301b461fb300ff
|
|
| BLAKE2b-256 |
f3c772e7ca19f0b390a5569ac2abecb4b2894ec373aa8a155c2c9a6c34ca7be2
|