code_graph / README.md
tlarsson's picture
Update README.md
763a717 verified
|
raw
history blame
2.39 kB
metadata
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 ast module
  • 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_state reads/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

  1. Launch the app or clone this repo
  2. Upload one or more .py files
  3. Select the "main" or top-level function to explore
  4. Interact with the graph and table to trace logic

πŸ›  Tech Stack

  • 🐍 Python
  • πŸ“¦ Dash & Plotly
  • 🧠 ast module (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