Smartly generates requirements.txt for Python projects with no virtual environment
Project description
ReqDev
ReqDev is a smart Python package that analyzes your Python projects and automatically generates requirements.txt files based on actual imports used in your code.
Problem
Have you ever:
- Deleted a virtual environment without saving your dependencies?
- Inherited a project without a requirements file?
- Wanted to clean up your requirements.txt to only include what you're actually using?
ReqDev solves these problems by scanning your Python code and identifying the packages you need.
Features
- 🔍 Accurate Detection: Scans Python files and notebooks to detect import statements
- 🧠 Smart Mapping: Correctly maps import names to PyPI package names (knows
cv2isopencv-python, etc.) - 📦 Version Detection: Optionally includes the exact version of each package
- 📑 Jupyter Support: Analyzes Jupyter notebooks for imports
- 🚀 Fast: Quickly scans even large codebases
- 🔧 Configurable: Easy to customize via CLI flags
- 🎨 Beautiful Output: Colorful terminal display of results
- 🔄 Smart Local Import Filtering: Excludes your project's local modules from requirements
- 🧩 Implicit Dependency Detection: Identifies dependencies not directly imported (like pymysql, pysql, pillow)
- 🕵️ Deep SQL Detection: Examines file contents to detect SQL-related libraries even when not imported
- 🛡️ Compatibility Checks: Automatically filters out packages known to be problematic with your Python version
- 🌱 Environment File Detection: Automatically adds python-dotenv when .env files are present
- 📈 Latest Versions: Fetches the latest compatible versions from PyPI
Installation
pip install reqdev
Usage
Basic usage:
reqdev
This will analyze the current directory and create a requirements.txt file.
Advanced Usage
# Specify a different project directory
reqdev --path /path/to/your/project
# Specify a different output file
reqdev --output dependencies.txt
# Generate requirements without version numbers
reqdev --no-versions
# Use latest versions from PyPI instead of installed versions
reqdev --latest
# Temporarily install packages to get precise versions
reqdev --install
# Skip Jupyter notebooks
reqdev --no-notebooks
# Disable implicit dependency detection
reqdev --no-implicit
# Filter out packages known to be problematic with your Python version
reqdev --compat
# Manually exclude specific packages
reqdev --exclude pysql mysql-python
# Enable verbose output
reqdev --verbose
# Show detailed debugging information
reqdev --debug
How It Works
- ReqDev recursively finds all Python files in your project
- It identifies local modules to exclude from requirements
- It parses each file using Python's AST to extract import statements
- It filters out standard library modules and local modules
- It maps import names to PyPI package names (e.g.,
cv2→opencv-python) - It detects implicit dependencies based on project structure (like pymysql, pysql for database projects)
- It detects configuration files like .env and .flaskenv
- It filters out problematic packages based on your Python version (if --compat is used)
- It fetches the latest compatible versions from PyPI (if --latest is used)
- It determines package versions (if enabled)
- It generates a properly formatted requirements.txt file
Advantages Over Alternatives
- More Accurate: Better mapping of import names to PyPI packages than tools like
pipreqs - Smarter Filtering: Detects and excludes your project's local modules from requirements
- Implicit Dependencies: Identifies dependencies that aren't directly imported but needed
- Deep Content Analysis: Examines file content to detect SQL usage patterns
- Compatibility Awareness: Filters out packages known to be problematic with your Python version
- Latest Versions: Can fetch the latest compatible versions from PyPI
- Config File Detection: Automatically includes python-dotenv when environment files are present
- Handles Jupyter: Support for analyzing
.ipynbfiles - Flexible Version Control: Can generate with or without version pinning
- Smart Install Option: Can temporarily install packages to determine exact versions
- Colorful UI: Easy-to-read terminal output
- Debugging Support: Debug flag helps troubleshoot dependency detection
Implicit Dependencies
ReqDev can detect implicit dependencies based on project structure:
- Environment Files: Adds
python-dotenvwhen .env, .flaskenv or similar files are found - MySQL/Database: Detects
pymysql,mysql-connector-pythonif SQL files or patterns are present - Django: Adds common Django dependencies like
pillowanddjango-crispy-forms - Flask: Adds dependencies like
gunicornandflask-login - Data Science: Ensures
matplotlibis included with pandas/numpy projects
You can disable this feature with --no-implicit if needed.
Compatibility Handling
ReqDev can automatically filter out packages known to cause installation problems:
- pysql: Incompatible with Python 3.7+ (syntax issues)
- pysqlite3: Most users should use the built-in sqlite3 module
- mysql-python: Deprecated, replaced by mysql-connector-python
- distribute: Merged into setuptools
- And others...
Enable this feature with --compat to avoid installation errors.
Version Management
ReqDev offers several options for handling package versions:
- Default: Uses versions of currently installed packages
- --no-versions: Generates requirements without version constraints
- --latest: Fetches the latest compatible versions from PyPI (recommended)
- --install: Temporarily installs packages to determine versions
Using --latest is recommended for most projects as it ensures your requirements file includes the most up-to-date compatible versions.
Troubleshooting
If a package isn't being detected:
- Try running with the
--debugflag:reqdev --debug - Check that any files containing SQL-related content are accessible
- Make sure the import name is correctly mapped in our database
- For SQL libraries specifically, we now scan both filenames and content
If you encounter installation errors with the generated requirements.txt:
- Try running with the
--compatflag to exclude problematic packages - Use
--exclude package_nameto manually exclude specific problematic packages - Check if the package is compatible with your Python version
- Try using
--latestto get the most up-to-date versions
Development
To contribute to ReqDev:
- Clone the repository
- Install development dependencies:
pip install -e ".[dev]" - Run tests:
pytest - Submit a pull request
License
MIT
Credits
Built with love by Naman Garg
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 reqdev-0.1.3.tar.gz.
File metadata
- Download URL: reqdev-0.1.3.tar.gz
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac283e29c191b8b31577dfdeb6ed96689e0e2f1d536663b752a90d0be66019bc
|
|
| MD5 |
4a28e54ff1e9ad0f8b6f8cb050458457
|
|
| BLAKE2b-256 |
200464142f37647a733fbb98ab2775bf47ec3070a6d2b773c025deb5e026ae45
|
File details
Details for the file reqdev-0.1.3-py3-none-any.whl.
File metadata
- Download URL: reqdev-0.1.3-py3-none-any.whl
- Upload date:
- Size: 17.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f196e5a002ce06f1f95b424e5477264a8b98b5bc7f67a91e2b2318f043a83d9
|
|
| MD5 |
6a65d60dc24b7bcc0cd9f67dc156a98c
|
|
| BLAKE2b-256 |
6f2f0c401f6342f70dcd20d37980bf610a991d9b2bf268c8ea124489a1312257
|