Example Weaknesses Overview#
This notebook demonstrates how to use the Python Code Audit APIs to analyze and visualize security weaknesses detected in a codebase.
We focus on two key visualizations:
Weakness distribution across the entire project
Per-file issue overview to identify high-risk files
These plots help prioritize security reviews and refactoring efforts.
Import APIs#
We import two visualization functions and the scan interface:
filescan→ performs a SAST scan on a packageweaknesses_overview→ aggregates common weaknessessast_files_overview→ shows issues per file
These APIs are designed to work together: Scan → Aggregate → Visualize
from codeaudit.altairplots import weaknesses_overview, sast_files_overview # Generates an interactive visualization from scan results
from codeaudit.api_interfaces import filescan #Used to perform a scan
Enable Interactive Rendering#
The visualizations use Altair + Panel for interactivity.
Panel is required to properly render charts inside notebooks. Panel is currently NOT installed when installing Python Code Audit, so install it with:
pip install panel
#To display Panel UI things in a notebook, the following lines are needed
import panel as pn
pn.extension()
Choose a Target Package#
Specify the Python package you want to analyze.
This can be:
A package from PyPI
A local project
Example below uses a small public package for demonstration.
packagename = "smolagents" #You can use any Python package present on PyPI.org, or a local package.
Run Security Scan#
The filescan API analyzes the package and extracts:
File-level metadata
Complexity metrics
Detected security weaknesses (SAST findings)
The result is a structured dictionary used by visualization APIs.
scanresult = filescan(packagename)
Visualize Common Weaknesses#
The weaknesses_overview plot shows the most frequent security patterns
across the entire codebase.
What this shows:#
Common risky constructs (e.g.
exec,subprocess,assert)Frequency of each issue
Top findings highlighted for quick inspection
Why it matters:#
This helps identify systematic security risks and recurring anti-patterns that should be addressed globally.
weaknesses_overview(scanresult)
Interpretation Guide#
Higher bars → more frequent usage → higher audit priority
Top 5 highlighted → most critical patterns to review first
Use this plot to:
Detect insecure coding habits
Guide secure coding training
Prioritize remediation efforts
Visualize Issues Per File#
The sast_files_overview plot shows how security issues are distributed
across individual files.
What this shows:#
Number of issues per file
Relative risk concentration
File complexity (via tooltip)
Why it matters:#
This helps identify high-risk files that require immediate attention.
sast_files_overview(scanresult)
Interpretation Guide#
Files with more issues → higher audit priority
Combine with complexity to identify:
Hard-to-maintain risky files
Refactoring candidates
Recommended workflow:#
Start with top files
Review findings in detail
Refactor or secure critical code paths
Use Cases#
These visualizations are useful for:
🔍 Security audits → Quickly identify risk hotspots
🧹 Refactoring → Target complex + vulnerable files
👥 Code reviews → Focus reviewer effort
🚀 CI/CD → Track security trends over time
In this notebook is shown:
How to run a SAST scan using
filescanAggregate weaknesses across a codebase
Visualize security risks using interactive plots
Identify high-risk files and patterns
Hint
The Python Code Audit APIs enable fast, visual security analysis directly in Python security workflows.