Skip to main content

Scan project source files and populate requirements.txt – with PyPI search and interactive resolution.

Project description

python-auto-req

Scan your Python project's .py and .ipynb files, discover every third-party package that is actually imported, and add them to requirements.txt.

Only packages explicitly referenced in your source files are considered. Packages installed in .venv but never imported are ignored.


Features

  • Recursively scans .py and .ipynb files (skips .venv, .git, __pycache__, etc.)
  • Uses the active Python environment to resolve module → distribution name + version
  • Falls back to a live PyPI search for unknown modules with an interactive menu:
    • Pick from top-5 results ranked by n-gram similarity
    • Auto-select top match ([a] or --auto)
    • Enter a name manually ([m])
    • Skip ([s]) or quit ([q])
  • Offers to run pip install -r requirements.txt after writing

Installation

pip install python-auto-req

Or from source:

git clone https://github.com/Amit-Roy/python-auto-req
cd python-auto-req
pip install -e .

Usage

# Preview what would be added (dry-run, interactive)
auto-req

# Write requirements.txt
auto-req --dry-run 0

# Write requirements.txt, auto-pick top PyPI match for unknowns
auto-req --dry-run 0 --auto

# Scan a specific directory
auto-req --dir /path/to/project --dry-run 0

Or via Python:

python -m auto_req --dry-run 0

CLI options

Option Default Description
--dry-run 0|1 1 1 = preview only; 0 = write to file
--auto off Always pick the top PyPI match (no prompts)
--dir DIR . Project root to scan
--requirements FILE ./requirements.txt Path to requirements.txt

Interactive resolution example

  Unrecognised module: 'yfinance'
  Searching PyPI for 'yfinance'... 5 result(s).
  Top PyPI matches:
    [1] yfinance       (similarity 1.00)
    [2] yfinance-cache (similarity 0.78)
    [3] yfinance-ez    (similarity 0.72)
    ...

  [1-5] select a match above
  [a]   auto-select top match for ALL remaining unknowns
  [m]   enter the correct dist name manually
  [s]   skip  (omit from requirements, continue)
  [q]   quit  (stop resolution now)

  Your choice: 1

Development

pip install -e ".[dev]"
pytest

MIT License

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

python_auto_req-0.4.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

python_auto_req-0.4.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file python_auto_req-0.4.0.tar.gz.

File metadata

  • Download URL: python_auto_req-0.4.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for python_auto_req-0.4.0.tar.gz
Algorithm Hash digest
SHA256 14ab787c9a53a5bf720b7c13516d28b1fbffac14004bc2c968f61c94f0fd7527
MD5 704ea93bcfc172c63721301d0680279f
BLAKE2b-256 b5dc02da1abffbadfa4d0dbc7d153c235fc9fe5f40ea13621d75f76449e48cab

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_auto_req-0.4.0.tar.gz:

Publisher: publish.yml on Amit-Roy/python-auto-req

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file python_auto_req-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for python_auto_req-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2306fa5f79d3ad182f8966b8cabfb998b7e59425879d66e499c530671c7e42f
MD5 5742405696f1313d0fd186ed490adb5d
BLAKE2b-256 676b7224a6c4cf1dd80e0505b21dd8516aa947e36f78b101a21e160d87a86d3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for python_auto_req-0.4.0-py3-none-any.whl:

Publisher: publish.yml on Amit-Roy/python-auto-req

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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