A colorful cfg for python executables.
Python3 control flow graph generator
StatiCFG is a package that can be used to produce control flow graphs (CFGs) for Python 3 programs. The CFGs it generates can be easily visualised with graphviz and used for static analysis. This analysis is actually the main purpose of the module, hence the name of StatiCFG.
Below is an example of a piece of code that generates the Fibonacci sequence and the CFG produced for it with StatiCFG.
def fib(): a, b = 0, 1 while True: yield a a, b = b, a + b fib_gen = fib() for _ in range(10): next(fib_gen)
./examples/ for more examples
To install simply run
pip3 install ccfg
It can be used three ways:
The default command is ccfg:
This will create a <file>_cfg.png file, which contains the colored cfg of the file.
cfg script present in the wrapper/ folder of this repository can be used to directly generate the CFG of some Python program and visualise it.
python3 ccfg path_to_my_code.py
To use StatiCFG, simply import the module in your Python interpreter or program, and use the
staticfg.CFGBuilder class to build CFGs.
For example, to build the CFG of a program defined in a file with the path ./example.py, the following code can be used:
from staticfg import CFGBuilder cfg = CFGBuilder().build_from_file('example', './example.py')
This returns the CFG for the code in ./example.py in the
The first parameter of
build_from_file is the desired name for the CFG, and the second one is the path to the file containing the source code.
The produced CFG can then be visualised with:
The first paramter of
build_visual is the desired name for the DOT file produced by the method, and the second one is the format to use for the visualisation.
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size ccfg-0.1.8.8-py3-none-any.whl (61.6 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size ccfg-0.1.8.8.tar.gz (62.6 kB)||File type Source||Python version None||Upload date||Hashes View|