Skip to main content

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

  1. Scan: Recursively walks through your project directory finding all .py files
  2. Parse: Uses Python's ast module to safely parse each file and extract import statements
  3. Filter: Removes standard library modules using a comprehensive built-in list
  4. 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

  1. Clone the repository
  2. Create a virtual environment: python -m venv venv
  3. Activate it: source venv/bin/activate (Linux/Mac) or venv\Scripts\activate (Windows)
  4. Install in development mode: pip install -e .
  5. Install test dependencies: pip install pytest
  6. Run tests: python -m pytest tests/ -v

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reqsgen-0.1.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reqsgen-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

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

Hashes for reqsgen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65866c51442abfbc30c81c0c8e83d2c80cce2004928ef6e89d3eb574039db76c
MD5 009aa87cef7356524573d65819f88cfa
BLAKE2b-256 309f327692bfde7bd7b6231393a72102e826140641c77b5332328db8a1bb2cc9

See more details on using hashes here.

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

Hashes for reqsgen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aae8500e8d2363c3bdc5a0630887153d0b134c14774e6a56d76ff8437118b12b
MD5 3364527b3aab2a5b3f301b461fb300ff
BLAKE2b-256 f3c772e7ca19f0b390a5569ac2abecb4b2894ec373aa8a155c2c9a6c34ca7be2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page