Skip to main content

Reads your Python files and builds a requirements.txt automatically — without running your code or guessing package names.

Project description

reqbuild

Reads your Python files and builds a requirements.txt automatically — without running your code or guessing package names.

PyPI version Python License: MIT


Features

  • 🔍 Reads your source files directly — finds every import statement without executing your code
  • 🌐 Resolves real package names — uses the pipreqs database + a live PyPI check as fallback
  • 🚫 No dependencies — only the Python standard library, nothing extra to install
  • 🔘 Detects optional imports — spots packages wrapped in try/except ImportError and marks them separately
  • 🎛️ Flexible CLI — control scope, exclusions, output format, and more

Installation

pip install reqbuild

Quick Start

# Scan only the current folder
reqbuild generate

# Scan everything recursively
reqbuild generate -a

# Preview without writing a file
reqbuild generate -a --print

CLI Reference

Command / Flag Description
generate Scan the current folder .py files
-a, --all Scan the current folder and all subdirectories recursively
-e DIR Exclude a directory name (repeatable: -e tests -e docs)
-ef FILE Exclude a specific filename (repeatable: -ef conftest.py)
-o FILENAME Output filename (default: requirements.txt). Use .in for pip-compile
--print Print resolved dependencies to stdout instead of writing a file
--optional Detect imports inside try/except ImportError and list them as comments
--no-network Offline mode — skip pipreqs download and PyPI checks
-h, --help Show help for this command

Examples

# Generate requirements.in (pip-compile compatible)
reqbuild generate -a -o requirements.in

# Exclude test and docs directories
reqbuild generate -a -e tests -e docs

# Exclude a specific file
reqbuild generate -a -ef setup.py

# Detect optional imports (try/except ImportError)
reqbuild generate -a --optional

# Offline mode (no network calls)
reqbuild generate -a --no-network

# Preview all dependencies without writing
reqbuild generate -a --print

Optional import detection

With --optional, reqbuild will detect imports wrapped in try/except ImportError:

import requests          # required — goes to requirements.txt

try:
    import ujson         # optional — listed as a comment
except ImportError:
    import json as ujson

Output (requirements.txt):

requests

# ─── Optional dependencies (detected inside try/except ImportError) ───
# ujson

Default ignored directories

reqbuild automatically ignores:

.venv, venv, .env, env, __pycache__, .git, .hg, .svn, .tox, .nox, dist, build, site-packages, .mypy_cache, .pytest_cache, .ruff_cache, node_modules, .eggs

Add more with -e:

reqbuild generate -a -e migrations -e fixtures

Python API

reqbuild can also be used as a library:

from reqbuild import scan, resolve, write_file

scan_result = scan(root=".", recursive=True, detect_optional=True)
external_names = [r.name for r in scan_result.imports]

resolve_result = resolve(external_names)
write_file(resolve_result, "requirements.txt")

License

MIT

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

reqbuild-0.1.1.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.

reqbuild-0.1.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file reqbuild-0.1.1.tar.gz.

File metadata

  • Download URL: reqbuild-0.1.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for reqbuild-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cc62a86caeaa2c46e12e914f8e11356fdc8430998f41c6069d3384cd38a16e9d
MD5 ecad3c1e1d61f2611e54f81a78a71d09
BLAKE2b-256 466ef43ecdd832e367c167507a7cc5eb6a7a2c2d53dc7c3aad8c095f291cc5ed

See more details on using hashes here.

File details

Details for the file reqbuild-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: reqbuild-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for reqbuild-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 17038dccd35ec82438a00968ba949edb05511588dcfb536622c006fd599ffdba
MD5 31655be018c0385e786cf027fbcdde6b
BLAKE2b-256 cf10c6ce210a1ebdbd49b751853e04bfd4eb8eb73a2d31697bb99fd87607be26

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