Validate, lint, sort, and compare Python requirements.txt files. Pure stdlib — no external dependencies required.
Check a requirements file for format errors, invalid specifiers, duplicates, and problematic patterns.
bash
python3 scripts/requirements-checker.py validate requirements.txt
# JSON output for automation
python3 scripts/requirements-checker.py validate requirements.txt --format json
# Strict mode — exit 1 on any issue (CI)
python3 scripts/requirements-checker.py validate requirements.txt --strict
All validation checks plus best-practice rules: unpinned deps, missing upper bounds, VCS deps, non-alphabetical order, mixed operator styles.
bash
python3 scripts/requirements-checker.py lint requirements.txt
# Markdown output (for PR comments, reports)
python3 scripts/requirements-checker.py lint requirements.txt --format markdown
# Strict mode — exit 1 on warnings too
python3 scripts/requirements-checker.py lint requirements.txt --strict
# Ignore specific rules
python3 scripts/requirements-checker.py lint requirements.txt --ignore unpinned --ignore no-upper-bound
Find packages listed more than once (case-insensitive, PEP 503 normalised).
bash
python3 scripts/requirements-checker.py duplicates requirements.txt
python3 scripts/requirements-checker.py duplicates requirements.txt --format json
Sort requirements alphabetically. By default writes to stdout; use --write to update the file in-place.
bash
# Preview sorted output
python3 scripts/requirements-checker.py sort requirements.txt
# Write sorted file in-place
python3 scripts/requirements-checker.py sort requirements.txt --write
Diff two requirements files — shows added, removed, and changed packages with version changes.
bash
python3 scripts/requirements-checker.py compare requirements.txt requirements-new.txt
python3 scripts/requirements-checker.py compare base.txt updated.txt --format markdown
OptionDescription--format text|json|markdownOutput format (default: text)--strictExit code 1 on any issue, including warnings/info (CI mode)--ignore RULEIgnore a named rule; repeatable
RuleSeverityDescriptioninvalid-formaterrorLine doesn't match PEP 508invalid-specifiererrorUnknown operator or unparseable version specduplicate-packageerrorSame package name appears more than onceeditable-installwarning-e editable installs in production requirementsvcs-dependencywarninggit+, hg+, svn+, bzr+ URL dependenciescustom-index-urlwarning--index-url / --extra-index-url presenturl-dependencyinfoDirect URL dependenciesrequirement-includeinfo-r nested includestrailing-whitespaceinfoLine has trailing spaces or tabswhitespace-only-lineinfoLine contains only whitespacemissing-final-newlineinfoFile doesn't end with newline
RuleSeverityDescriptionunpinnedwarningDependency has no version specifierno-upper-boundwarning>= used without a < / <= upper boundnon-alphabeticalwarningPackages are not in alphabetical ordermixed-operatorsinfoFile mixes == exact pins and >= range specifiers
text
File: requirements.txt
[ERROR] line 4 (duplicate-package) Duplicate package 'requests' (first seen on line 2)
requests==2.31.0
[WARNING] line 7 (no-upper-bound) 'django' uses >= without an upper bound
django>=4.0
[WARNING] line 1 (non-alphabetical) 'zope' is out of alphabetical order
zope==5.0
Summary: 3 issue(s) — 1 error(s), 2 warning(s), 0 info(s)