Run Bandit and Semgrep, normalize findings, and produce deterministic security audit reports.
Project description
ai-code-sec-audit
ai-code-sec-audit is a lightweight Python package and CLI that runs Bandit and Semgrep,
normalizes findings into a stable JSON schema, computes a deterministic score, and writes a
reproducible report.
Install
pip install ai-code-sec-audit
CLI usage
ai-code-sec-audit audit path/to/file.py -o report.json
ai-code-sec-audit audit path/to/dir -o report.json -f high
Options use short flags:
-o: output JSON path (required)-p: profile (default:default)-f: fail threshold (critical|high|medium|low|info)-P: pretty-print JSON
Python API
from ai_code_sec_audit import audit_path
report = audit_path("path/to/file.py", profile="default", fail_on="high")
print(report.summary.score)
Output schema
Canonical JSON report fields:
meta: tool_version, timestamp, target, profile, how_to_reproducesummary: score, total_findings, counts, should_failfindings[]: tool, rule_id, title, description, severity, confidence, cwe, file, start_line, end_line, fingerprint, references
Reproducible command
meta.how_to_reproduce contains the exact command with resolved target/output paths and selected
flags to reproduce the same report.
Sample JSON snippet
{
"meta": {
"tool_version": "0.1.0",
"target": "/abs/path/examples/vuln_python/app.py",
"profile": "default",
"how_to_reproduce": "ai-code-sec-audit audit /abs/path/examples/vuln_python/app.py -o /abs/path/report.json -p default"
},
"summary": {
"score": 86,
"total_findings": 2,
"counts": {
"critical": 0,
"high": 1,
"medium": 1,
"low": 0,
"info": 0
},
"should_fail": true
}
}
Scoring
Score starts at 100 and deducts:
- critical:
20 - high:
10 - medium:
4 - low:
1 - info:
0
Final score is clamped to 0..100.
Fail-on behavior
critical: fail if any critical findingshigh: fail if any critical/highmedium: fail if any critical/high/mediumlow: fail if any critical/high/medium/lowinfo: fail if any finding exists
CLI exits with status code 2 when threshold is met.
Scanner behavior
- Bandit command:
- directory:
bandit -r <target> -f json - file:
bandit <target> -f json
- directory:
- Semgrep command:
semgrep --config auto --json <target> - If scanner binaries are missing, warnings are printed and scanning continues.
Limitations (v0.1.0)
- No HTML reports
- No SARIF output
- Only Bandit + Semgrep are supported
- No advanced configuration system
Roadmap
- Additional scanner integrations
- Config file support
- Optional report enrichments and diff mode
Sample run artifacts
This repository includes sample-run inputs and outputs:
- Vulnerable input:
examples/vuln_python/app.py - Safer input:
examples/safe_python/app.py - Reproducible run script:
examples/sample_runs/run_samples.sh - Captured run logs:
examples/sample_runs/vuln_run.txt,examples/sample_runs/safe_run.txt - Generated reports:
examples/sample_runs/vuln_report.json,examples/sample_runs/safe_report.json
Run from repo root:
./examples/sample_runs/run_samples.sh
Publish to PyPI
This project is now configured for PyPI publishing with:
- package metadata in
pyproject.toml - reproducible
sdist+wheelbuilds viahatchling - a GitHub Actions workflow at
.github/workflows/publish.ymlthat uploads on release
One-time setup
- Create a project on PyPI named
ai-code-sec-audit. - In the PyPI project settings, enable Trusted Publishing for your GitHub repository
and the workflow file
.github/workflows/publish.yml. - Update
project.urlsinpyproject.tomlif your repository URL differs.
Release flow (recommended)
- Bump
src/ai_code_sec_audit/version.py. - Commit and tag a release in GitHub.
- Publish a GitHub Release (or run the workflow manually).
- The workflow builds, validates, and uploads the package to PyPI.
Manual upload (fallback)
python -m pip install --upgrade build twine
python -m build
twine check dist/*
twine upload dist/*
Development
ruff check .
ruff format .
mypy src
pytest
python -m build
twine check dist/*
License
MIT.
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 ai_code_sec_audit-0.1.0.tar.gz.
File metadata
- Download URL: ai_code_sec_audit-0.1.0.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2f1b126589502fa1121a6166f0fd7543699e093f8446dd7f7fbdac6bfd62ba6
|
|
| MD5 |
d9bcfd04c54dbdc47b6c43f7146d11c7
|
|
| BLAKE2b-256 |
81b10b39adca697a6ecd7fdb91bee8ce08e93fe6e4d5ff1e5aea86b3afa90a95
|
Provenance
The following attestation bundles were made for ai_code_sec_audit-0.1.0.tar.gz:
Publisher:
publish.yml on widdendream/ai-code-sec-audit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_code_sec_audit-0.1.0.tar.gz -
Subject digest:
d2f1b126589502fa1121a6166f0fd7543699e093f8446dd7f7fbdac6bfd62ba6 - Sigstore transparency entry: 952369042
- Sigstore integration time:
-
Permalink:
widdendream/ai-code-sec-audit@0b54c7de75a182332bedc65ab9cfe7731b964d6f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/widdendream
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0b54c7de75a182332bedc65ab9cfe7731b964d6f -
Trigger Event:
release
-
Statement type:
File details
Details for the file ai_code_sec_audit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ai_code_sec_audit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16ef7c9594e1ba6e59e8a2fed41a5bbc9490e843a6bdd44b59584be43ef7639a
|
|
| MD5 |
ae87aac928076a8384f75c710acdde20
|
|
| BLAKE2b-256 |
cf441010f30731f78b9983c329246cd27b806d22d56c506e7b29e1605b189b70
|
Provenance
The following attestation bundles were made for ai_code_sec_audit-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on widdendream/ai-code-sec-audit
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_code_sec_audit-0.1.0-py3-none-any.whl -
Subject digest:
16ef7c9594e1ba6e59e8a2fed41a5bbc9490e843a6bdd44b59584be43ef7639a - Sigstore transparency entry: 952369047
- Sigstore integration time:
-
Permalink:
widdendream/ai-code-sec-audit@0b54c7de75a182332bedc65ab9cfe7731b964d6f -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/widdendream
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0b54c7de75a182332bedc65ab9cfe7731b964d6f -
Trigger Event:
release
-
Statement type: