Example Code Risk Heatmap#
This notebook demonstrates how to use the codeaudit Python API to perform a Static Application Security Testing (SAST) scan and visualize results using an interactive Code Risk Heatmap.
The heatmap helps identify high-risk files by combining:
Code complexity
Lines of code (size)
A derived risk score
This guide is intended for:
Security engineers performing code audits
Developers integrating SAST into workflows
API users exploring
codeauditcapabilities
What You Will Learn#
In this this notebook is shown:
Run a file-level security scan using the
codeauditAPIUnderstand the structure of scan results
Generate an interactive Altair-based heatmap
Identify high-risk files using dynamic thresholds
Integrate visualization into your own analysis workflows
from codeaudit.altairplots import complexity_heatmap # Generates an interactive visualization from scan results
from codeaudit.api_interfaces import filescan #Used to perform a scan
#To display Panel UI things in a notebook, the following lines are needed
import panel as pn
pn.extension()
packagename = "smolagents" #You can use any Python package present on PyPI.org, or a local package.
smolagents is a Python library that enables you to run powerful agents in a few lines of code. It is not free of weaknesses that can depending on the context turn into a vulnerability.
scanresult = filescan(packagename)
What This Visualization Shows
Files ranked by risk score
Two key metrics:
Complexity
Lines of code
Color intensity reflects magnitude
High-risk values are highlighted in red
complexity_heatmap(scanresult)
Interactive Controls#
The heatmap includes dynamic controls:
Sliders#
ComplexityThreshold → highlight complex files
LinesThreshold → highlight large files
Toggle#
✅ Show only high-risk files
Tip:#
Adjust thresholds to focus on:
Maintainability risks (complexity)
Scalability risks (file size)