Automatically generate requirements.txt from your Python project using AST analysis.
Project description
reqbuild
Automatically generate
requirements.txtfrom your Python project using AST analysis — no imports, no installation needed at scan time.
Features
- 🔍 AST-based — parses your source files without running them
- 🌐 Smart resolution — uses the pipreqs mapping + live PyPI fallback
- 🚫 Zero dependencies — only the Python standard library
- 🔘 Optional import detection — spots imports inside
try/except ImportErrorblocks - 🎛️ 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
reqbuild generate (alias: gen)
Scan Python files and generate a requirements file.
| Flag | Description |
|---|---|
-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 |
Global flags
| Flag | Description |
|---|---|
-V, --version |
Show the installed version |
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")
Publishing to PyPI
pip install build twine
# Build
python -m build
# Upload to TestPyPI first
twine upload --repository testpypi dist/*
# Upload to PyPI
twine upload dist/*
License
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 reqbuild-0.1.0.tar.gz.
File metadata
- Download URL: reqbuild-0.1.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcf76d2b2572384c2149338d7e198ae071fa058d21d028ed0ccde4400ccfb3ed
|
|
| MD5 |
905b6f4de44033abd5e615d5f6bc62e7
|
|
| BLAKE2b-256 |
9bc6a6bb2e238a3761db330ef18361e4f4b23a0893200375f778baf6ba73072a
|
File details
Details for the file reqbuild-0.1.0-py3-none-any.whl.
File metadata
- Download URL: reqbuild-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68eb9ca66090128e3bd7797f5792dc655749fff0462fbd8e7d69ee7f4d020220
|
|
| MD5 |
2a75078c51d3c6c3bb73814ea014ad69
|
|
| BLAKE2b-256 |
b3b74532bbef3704e7fd0309b06cc787ccc30797a8c212d8ecd2fa3f93c332d9
|