Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -7,4 +7,88 @@ sdk: docker
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# π» Code Graph
|
| 14 |
+
|
| 15 |
+
**Code Graph** is a visual tool that analyzes and displays function dependencies in Python code using AST-based static parsing.
|
| 16 |
+
|
| 17 |
+
Itβs ideal for developers, data scientists, and Streamlit users who want to understand how their functions interact β without needing to execute any code.
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## π What It Does
|
| 22 |
+
|
| 23 |
+
Upload one or more `.py` files, and this tool will:
|
| 24 |
+
|
| 25 |
+
- Parse the source code using Pythonβs built-in `ast` module
|
| 26 |
+
- Identify function definitions and their relationships
|
| 27 |
+
- Show which functions:
|
| 28 |
+
- Are called from others
|
| 29 |
+
- Read or write to `st.session_state`
|
| 30 |
+
- Take specific arguments and return specific values
|
| 31 |
+
- Display all this in a **fully interactive graph** and table
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## π§ What is AST?
|
| 36 |
+
|
| 37 |
+
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.
|
| 38 |
+
|
| 39 |
+
Code Graph uses ASTs to analyze code structure **without running the code**, making it safe and fast to use.
|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
## π Features
|
| 44 |
+
|
| 45 |
+
β
Upload one or more Python files
|
| 46 |
+
β
Auto-detect function calls and dependencies
|
| 47 |
+
β
Highlights:
|
| 48 |
+
|
| 49 |
+
- Function **arguments** and **return values** with inferred types (e.g. `df: pd.DataFrame`)
|
| 50 |
+
- Streamlit `session_state` **reads/writes**
|
| 51 |
+
- **Call order labels** on edges (`1`, `2`, `3`, β¦)
|
| 52 |
+
- **Thicker edges** for functions called multiple times
|
| 53 |
+
|
| 54 |
+
β
Export the graph as downloadable JSON
|
| 55 |
+
β
View everything in an interactive graph and sortable table
|
| 56 |
+
|
| 57 |
+
---
|
| 58 |
+
|
| 59 |
+
## π How to Use
|
| 60 |
+
|
| 61 |
+
1. Launch the app or clone this repo
|
| 62 |
+
2. Upload one or more `.py` files
|
| 63 |
+
3. Select the "main" or top-level function to explore
|
| 64 |
+
4. Interact with the graph and table to trace logic
|
| 65 |
+
|
| 66 |
+
---
|
| 67 |
+
|
| 68 |
+
## π Tech Stack
|
| 69 |
+
|
| 70 |
+
- π Python
|
| 71 |
+
- π¦ Dash & Plotly
|
| 72 |
+
- π§ `ast` module (for static code parsing)
|
| 73 |
+
- π Cytoscape.js (for interactive graph rendering)
|
| 74 |
+
|
| 75 |
+
---
|
| 76 |
+
|
| 77 |
+
## πββοΈ About the Author
|
| 78 |
+
|
| 79 |
+
Created by **Tomas Larsson**, a data scientist and creator of
|
| 80 |
+
[**my.moneytoolbox.com**](https://my.moneytoolbox.com) β a blog covering:
|
| 81 |
+
|
| 82 |
+
- Tax-optimized investing
|
| 83 |
+
- Retirement modeling
|
| 84 |
+
- Financial tools for DIY investors
|
| 85 |
+
|
| 86 |
+
---
|
| 87 |
+
|
| 88 |
+
## π€ Deployment (Docker-based)
|
| 89 |
+
|
| 90 |
+
If you're running locally:
|
| 91 |
+
|
| 92 |
+
```bash
|
| 93 |
+
docker build -t code-graph .
|
| 94 |
+
docker run -p 7860:7860 code-graph
|