Skip to main content

Visualize recursive Python functions as interactive call trees with timeline-based animation.

Project description

StackSprout

StackSprout demo

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:

  1. Tracing phase
    A decorator (@trace) records function entry, exit, and timing information during execution.
  2. 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 need python3-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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stacksprout-0.1.1.tar.gz (9.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stacksprout-0.1.1-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file stacksprout-0.1.1.tar.gz.

File metadata

  • Download URL: stacksprout-0.1.1.tar.gz
  • Upload date:
  • Size: 9.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for stacksprout-0.1.1.tar.gz
Algorithm Hash digest
SHA256 11814685aa6f05a2e9cbd6ce654771624c1a1ffebec31850b9ce3516c97c481f
MD5 aadb24a8999fc16ed18af809689b7e16
BLAKE2b-256 dd7fc91f33145ca583bdb5da1674c5dda05dd1baa924d779c2068a8d5cab8234

See more details on using hashes here.

File details

Details for the file stacksprout-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: stacksprout-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.5

File hashes

Hashes for stacksprout-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 84c3f2eae078eaf8a36c56942aaf14697824cbb59991b4b88282fc419fa7ffc7
MD5 9acc5c5fd52b7654031f2575e4e826db
BLAKE2b-256 7e8ae21a6ba347c37e8a4b6d3e80862687469413962ffa7c1d281f438924ac92

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page