StackSprout
StackSprout is a Python library for visualizing the execution of recursive functions as interactive call trees, with optional timeline-based animation.
It helps you see how recursion grows, branches, and unwinds — making it useful for learning, debugging, and exploration.
Unlike debuggers or profilers, StackSprout records execution first and visualizes it afterward, enabling deterministic playback and timeline control.
Perfect for students, educators, and developers who want to understand why recursive code behaves the way it does.
Why Use StackSprout?
StackSprout makes recursion visible. Unlike debuggers that show the state at a single point in time, or profilers that focus on performance metrics, StackSprout lets you step through the entire call lifecycle of recursive functions. This makes it an invaluable tool for learning, teaching, and debugging recursive algorithms.
Features
- Visualize recursive calls as an interactive, clean tree layout
- Static and animated execution modes
- Timeline scrubbing, stepping, and playback controls
- Interactive canvas with pan, zoom, and click-to-inspect nodes
- Synchronized tree and hierarchy views
- Works with any recursive Python function
Installation
Install from PyPI:
pip install stacksprout
Or install from source:
pip install .
Quick Example
from stacksprout import trace, visualize_tree
@trace
def fib(n):
if n <= 1:
return 1
return fib(n - 1) + fib(n - 2)
fib(6)
visualize_tree(fib)
This opens an interactive window where you can scrub, step through, and replay the recursive call tree for fib(6).
Design Overview
StackSprout operates in two phases:
- Tracing phase
A decorator (@trace) records function entry, exit, and timing information during execution. - Visualization phase
After execution, the recorded data is turned into a visual call tree, which can be explored statically or animated over time.
This design ensures deterministic, debuggable visualizations without interfering with runtime behavior.
Usage Notes
- The decorated function must be executed before calling
visualize_tree(). - If no trace data exists, StackSprout displays a helpful message and exits cleanly.
- Mutual recursion and multi-root call trees are not supported in v1.
Examples
Additional examples can be found in the examples/ directory:
- Fibonacci
- Factorial
- Custom recursive functions
Requirements
- Python 3.10 or newer
tkinter(included with most Python installations; Linux users may needpython3-tk)
License
This project is licensed under the MIT License. See the license on GitHub.
About
Built as an educational and exploratory tool for understanding recursion and call stacks. Feedback is welcome.
Metadata
Release files for stacksprout 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stacksprout-0.1.1.tar.gz | 9.3 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stacksprout-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 MB
Release files / stacksprout-0.1.1.tar.gz
| Download URL | stacksprout-0.1.1.tar.gz |
|---|---|
| Size | 9.3 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
11814685aa6f05a2e9cbd6ce654771624c1a1ffebec31850b9ce3516c97c481f
|
|
BLAKE2b-256 checksum How to use checksums |
dd7fc91f33145ca583bdb5da1674c5dda05dd1baa924d779c2068a8d5cab8234
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.5
|
Release files / stacksprout-0.1.1-py3-none-any.whl
| Download URL | stacksprout-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84c3f2eae078eaf8a36c56942aaf14697824cbb59991b4b88282fc419fa7ffc7
|
|
BLAKE2b-256 checksum How to use checksums |
7e8ae21a6ba347c37e8a4b6d3e80862687469413962ffa7c1d281f438924ac92
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.5
|