pip install bandit★Extras:bandit[toml](read config frompyproject.toml),bandit[sarif](SARIF output),bandit[baseline]. Python 3.10+.bandit -r ./src★The one command you need:-rrecurses a directory. Scans all.pyfiles and prints findings grouped by severity.bandit myfile.pyScan a single file (no-rneeded).bandit --version,bandit --help.bandit -r . -x './tests,./.venv'★-x/--excludeskips paths (comma-separated globs). Exclude tests, venvs, and vendored code.
bandit -r src -ll # report only MEDIUM+ severity★-l/-ll/-lllraise the minimum severity to report (LOW/MEDIUM/HIGH). Cuts noise fast.bandit -r src -ii # report only MEDIUM+ confidence★-i/-ii/-iiiraise the minimum confidence. Combine with-llto focus on high-signal findings.bandit -r src -q # quiet: only show findings-qsuppresses the per-file progress;-vfor verbose.--exit-zeroto never fail the process.bandit -r src -n 3 # lines of context around each issue-nsets how many code lines print around each finding.# bandit exits non-zero when it finds issues — good for CInoteA non-zero exit fails the build. Use--severity-level/--confidence-levelor a baseline to control what counts.