Spaces:
Sleeping
title: Code Graph
emoji: π»
colorFrom: red
colorTo: green
sdk: docker
pinned: false
π» Code Graph
Code Graph is a visual tool that analyzes and displays function dependencies in Python code using AST-based static parsing.
Itβs ideal for developers, data scientists, and Streamlit users who want to understand how their functions interact β without needing to execute any code.
π What It Does
Upload one or more .py files, and this tool will:
- Parse the source code using Pythonβs built-in
astmodule - Identify function definitions and their relationships
- Show which functions:
- Are called from others
- Read or write to
st.session_state - Take specific arguments and return specific values
- Display all this in a fully interactive graph and table
π§ What is AST?
AST stands for Abstract Syntax Tree β a structured representation of your source code as a tree. Each node represents a language construct like a function, loop, or assignment.
Code Graph uses ASTs to analyze code structure without running the code, making it safe and fast to use.
π Features
β
Upload one or more Python files
β
Auto-detect function calls and dependencies
β
Highlights:
- Function arguments and return values with inferred types (e.g.
df: pd.DataFrame) - Streamlit
session_statereads/writes - Call order labels on edges (
1,2,3, β¦) - Thicker edges for functions called multiple times
β
Export the graph as downloadable JSON
β
View everything in an interactive graph and sortable table
π How to Use
- Launch the app or clone this repo
- Upload one or more
.pyfiles - Select the "main" or top-level function to explore
- Interact with the graph and table to trace logic
π Tech Stack
- π Python
- π¦ Dash & Plotly
- π§
astmodule (for static code parsing) - π Cytoscape.js (for interactive graph rendering)
πββοΈ About the Author
Created by Tomas Larsson, a data scientist and creator of
my.moneytoolbox.com β a blog covering:
- Tax-optimized investing
- Retirement modeling
- Financial tools for DIY investors
π€ Deployment (Docker-based)
If you're running locally:
docker build -t code-graph .
docker run -p 7860:7860 code-graph