StaticFG is a Python library (current version 0.9.5) designed to generate control flow graphs (CFGs) for Python 3 programs. It parses Python source code, builds an Abstract Syntax Tree (AST), and then transforms it into a CFG, which can be visualized using Graphviz. The project is actively maintained with a moderate release cadence.
pip install staticfgVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to build a control flow graph from a Python string and attempt to visualize it as a PDF. Note that the Graphviz *system tool* (providing the `dot` command) must be installed and in your system's PATH for visualization to succeed.
Install Graphviz on your operating system (e.g., `sudo apt-get install graphviz` on Debian/Ubuntu, `brew install graphviz` on macOS, or download from graphviz.org for Windows). Then verify `dot -V` works in your terminal.
Simplify complex code structures if CFG output is unexpected, or manually verify the generated graph against the expected control flow for correctness.
Import the `CFG` class explicitly from its submodule: `from staticfg.cfg import CFG`.
Install Graphviz for your operating system (e.g., `sudo apt-get install graphviz` on Debian/Ubuntu, `brew install graphviz` on macOS, or download from graphviz.org for Windows). Ensure the `dot` command is accessible from your shell.
This is less common. Try simplifying the input Python code to isolate the problematic construct. Ensure the directory where `build_visual` attempts to save the output has write permissions.
Import `CFG` explicitly from `staticfg.cfg`: `from staticfg.cfg import CFG`.
Install the Python `graphviz` package: `pip install graphviz`.