Skip to main content

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_reproduce
  • summary: score, total_findings, counts, should_fail
  • findings[]: 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 findings
  • high: fail if any critical/high
  • medium: fail if any critical/high/medium
  • low: fail if any critical/high/medium/low
  • info: 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
  • 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 + wheel builds via hatchling
  • a GitHub Actions workflow at .github/workflows/publish.yml that uploads on release

One-time setup

  1. Create a project on PyPI named ai-code-sec-audit.
  2. In the PyPI project settings, enable Trusted Publishing for your GitHub repository and the workflow file .github/workflows/publish.yml.
  3. Update project.urls in pyproject.toml if your repository URL differs.
  1. Bump src/ai_code_sec_audit/version.py.
  2. Commit and tag a release in GitHub.
  3. Publish a GitHub Release (or run the workflow manually).
  4. 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.

Metadata

Release files for ai-code-sec-audit 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-code-sec-audit 0.1.0
File Size Uploaded Provenance
ai_code_sec_audit-0.1.0.tar.gz 9.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-code-sec-audit 0.1.0
File Interpreter ABI Platform
ai_code_sec_audit-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / ai_code_sec_audit-0.1.0.tar.gz

Download URL ai_code_sec_audit-0.1.0.tar.gz
Size 9.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d2f1b126589502fa1121a6166f0fd7543699e093f8446dd7f7fbdac6bfd62ba6
BLAKE2b-256 checksum
How to use checksums
81b10b39adca697a6ecd7fdb91bee8ce08e93fe6e4d5ff1e5aea86b3afa90a95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2026.

Transparency log

Release files / ai_code_sec_audit-0.1.0-py3-none-any.whl

Download URL ai_code_sec_audit-0.1.0-py3-none-any.whl
Size 12.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16ef7c9594e1ba6e59e8a2fed41a5bbc9490e843a6bdd44b59584be43ef7639a
BLAKE2b-256 checksum
How to use checksums
cf441010f30731f78b9983c329246cd27b806d22d56c506e7b29e1605b189b70
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2026.

Transparency log

Security for ai-code-sec-audit 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ai_code_sec_audit-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page