$ show bterwijn/memory_graph
memory_graph is a Python library for visualizing the structure of Python data as graphs, primarily used for debugging and teaching concepts like references, mutability, and shallow/deep copy. It takes any Python data (e.g., locals(), call stack frames) and generates a Graphviz-based graph (PDF, PNG, SVG) showing the hierarchical relationships and shared references. The library supports multiple node types (leaf, linear, key-value, table), configurable slicing to limit graph size, call stack visualization with IDE-specific stack frame filtering, and extensions for numpy, pandas, and PyTorch types. It is designed to be used interactively in debuggers (VS Code, PyCharm, etc.) or programmatically via functions like `show()`, `render()`, and `block()`. The codebase is well-structured with clean separation of concerns (node types, slicing logic, configuration, HTML table generation) and includes unit tests for core components.
The LLM identified 4 files worth highlighting for reuse:
Implements the `Slicer` class that defines which portions of a sequence to display (begin, middle, end) using either absolute counts or fractions. It produces a `Slices1D` object that can be merged and iterated. This component is self-contained, parameterized, and reusable in any project that needs to truncate or sample data for display or processing.
Provides a `List_View` class that offers a view into a sublist of a base list without copying elements. It supports indexing, slicing (with step=1), iteration, and length queries. This is a classic and reusable pattern for memory-efficient sublist operations, useful in algorithms that need to avoid data duplication.
Implements the `HTML_Table` class that builds HTML-like table strings for Graphviz nodes. It supports adding rows, columns, indices, values, references (with ports), and dots for truncation. The class handles orientation (row/column reversal) and produces edges for graph connections. This component is well-isolated and could be reused for generating HTML tables in other contexts, especially for Graphviz integration.
Defines `Slices1D` and `Slices2D` classes that represent collections of index ranges (slices) with support for merging, membership testing, and iteration. They also track dashed edges for missing references. The slicing logic is cleanly separated from the node visualization, making it reusable for any project that needs to manage and iterate over subsets of 1D or 2D data.