Skip to content

shzaiz/py-state-vis

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Python State Visualizer

Overview

The Visualizer class provides a powerful way to visualize Python objects, including their attributes and relationships, in a graphical format using the Graphviz DOT language. It handles various data types, including primitives, lists, dictionaries, and custom objects, allowing for a clear understanding of complex data structures.

Installation

To use the Visualizer, ensure you have the following dependencies installed:

pip install pydot

You may also need Graphviz installed on your system to render the graphs. You can download it from Graphviz's official site.

Usage

At the beginning your toy code, add

from visualizer import *

If you want it to trace at each step, using trace function is a good idea. For example, adding

# Trace function, call visualizer to inspect state
def trace_func(frame, event, arg):
    # avoid drawing too many states, only up to main function.
    # SURPRISE: The visualizer can visualize itself upon setting
    # valid_frames_frm to 0. (but the output will be really verbose).
    Visualizer().visualize_whole_state(valid_frames_frm=2, strict=True).write_png("test.png")
    input() # Pause the execution step
    return trace_func  

Or you may use Visualizer().visualize_whole_state(valid_frames_frm=2, strict=True).write_png("test.png") when a point of interest appears.

Visualizing Python state

About

A visualizer designed for educational purposes that illustrates memory layout during (simple) Python execution, helping to demonstrate fundamental memory structures and concepts.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages