Skip to main content

SAST (Static application security testing) Energy Monitor

PyPI version

A command-line tool to measure the energy consumption of static analysis scans (Bandit, Semgrep) on your codebase using Energibridge, with clear, colored output.

What it Does

This tool wraps bandit or semgrep scans within an energibridge measurement process. It runs the specified scan using predefined configurations bundled with the tool and displays:

  • The findings reported by Bandit or Semgrep.
  • The total energy consumed during the scan execution, as reported by Energibridge.
  • Colored output for better readability (errors in red, findings in yellow, success/summary in green/magenta).

Prerequisites

  • Python: Version 3.8 or higher.

  • Energibridge:

    • You must have the energibridge.exe (or your OS equivalent) executable installed and know its path. Energibridge needs to be obtained separately from its source.
    • Windows Setup (RAPL Service): Energibridge often relies on the RAPL (Running Average Power Limit) service to access energy data on Windows. If you haven't configured this before, you may need to install and start the service using Administrator privileges:
      # Open PowerShell or Command Prompt as Administrator
      
      # Create the service (Replace path if LibreHardwareMonitor.sys is elsewhere)
      sc create rapl type=kernel binPath="C:\path\to\your\LibreHardwareMonitor.sys"
      
      # Start the service
      sc start rapl
      
      • Download LibreHardwareMonitor.sys from here: https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/releases
      • Note: You only need to do this once. Verify the path to LibreHardwareMonitor.sys (which often comes with tools like LibreHardwareMonitor or potentially Energibridge's dependencies).
      • You can test if Energibridge is working correctly by running a simple command like energibridge.exe --summary timeout 5 in your terminal (as Admin if needed).
  • Bandit / Semgrep:

    • The specific scanner (bandit or semgrep) you intend to use must be installed in your Python environment and accessible from your system's PATH.

    • Install them if needed:

      pip install bandit semgrep
      

Installation

From PyPI:

pip install sast_energy_monitor

Usage

Run the tool from your command line:

sast_energy_monitor --energibridge-path /path/to/energibridge.exe \
            --repo-path /path/to/your/code/repository \
            --tool [bandit|semgrep] \
            --config-level [strict|loose]

Arguments:

  • energibridge-path: (Required) Absolute or relative path to your energibridge executable.

  • repo-path: (Required) Path to the root directory of the code repository you want to scan.

  • tool: (Required) Choose bandit or semgrep.

  • config-level: (Required) Choose strict or loose. This selects a predefined configuration file bundled with the tool.

Example:

# On Windows
sast_energy_monitor --energibridge-path C:\Tools\energibridge.exe
            --repo-path C:\MyProjects\MyApp
            --tool bandit
            --config-level strict

# On Linux/macOS
sast_energy_monitor --energibridge-path /usr/local/bin/energibridge \
            --repo-path ~/projects/my_app \
            --tool semgrep \
            --config-level loose

The tool will execute the scan, display the scanner's findings, and print the final energy consumption summary from Energibridge. Non-zero exit codes from scanners (indicating findings) are handled gracefully.

Bundled Configurations

This tool uses internal configuration files:

  • Bandit:

    • loose: Uses the bundled configs/.bandit_basic file.

    • strict: Uses the bundled configs/.bandit file.

  • Semgrep:

    • loose: Uses the bundled configs/.semgrep.yml file.

    • strict: Uses the Semgrep Registry ruleset p/bandit.

Currently it is not possible to override these configurations via command-line arguments.

Important Notes

  • Administrator Privileges: You need to run the sast-energy-monitor command itself with Administrator/root privileges for Energibridge to function correctly.

  • The accuracy of energy measurements depends heavily on Energibridge's capabilities and the underlying hardware support (like Intel RAPL).

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributors

Sustainable Software Engineering Group 10, TU Delft:

  • Yulin Chen
  • Ayush Kuruvilla
  • Sahar Marossi
  • Andrea Onofrei

Metadata

Release files for sast-energy-monitor 0.1.5

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

Source distribution (sdist)

Source distribution for sast-energy-monitor 0.1.5
File Size Uploaded Provenance
sast_energy_monitor-0.1.5.tar.gz 14.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for sast-energy-monitor 0.1.5
File Interpreter ABI Platform
sast_energy_monitor-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 26.4 kB

Release files / sast_energy_monitor-0.1.5.tar.gz

Download URL sast_energy_monitor-0.1.5.tar.gz
Size 14.0 kB
Tags Source
SHA-256 checksum
How to use checksums
cee917a3a13e68a77001d6b9aa65dd3def0b9befd8e21524bcb2b2122221f9d0
BLAKE2b-256 checksum
How to use checksums
b4b2f3f1da494d419c20ebeb6886577f6b9df08eda840460b65e599e2fba44ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / sast_energy_monitor-0.1.5-py3-none-any.whl

Download URL sast_energy_monitor-0.1.5-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c0cfcfff531f3cecca92ba08a8e79c78d7fc7c0cad99d1cffc7d883245b05c53
BLAKE2b-256 checksum
How to use checksums
c826bf70b79ccdb56d3596af8620f918fff376fce0535774a447f7baaf212092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Security for sast-energy-monitor 0.1.5

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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