Python AST Viewer
Visualize and explore the Abstract Syntax Tree of your scripts.
Why use this tool?
Use the AST Viewer to visually inspect the Abstract Syntax Tree of any Python script. It's the ultimate debugging and educational tool for developers building compilers, linters, or static analyzers.
def calculate_sum(a, b):
return a + b
x = calculate_sum(5, 10)Selling your Python App?
Don't let your software be pirated. With Licers.com, you can easily issue license keys, bind them to devices (HWID), and instantly validate licenses natively in Python.
- ✓ Free forever plan available
- ✓ Simple Python SDK integration
- ✓ Stop piracy instantly
Tool facts
- Supported Python
- Python 3.x (CPython ast via Pyodide)
- Input limit
- Limited only by your device
- Last reviewed
- 2026-08-25
What it can't do
- •Execute your code — it parses source into an abstract syntax tree only.
- •Parse code that has syntax errors (fix them first).
About Python AST Viewer
The Python AST Viewer parses your code into its Abstract Syntax Tree and displays the node hierarchy the interpreter actually works with. It's built for developers learning compiler and language internals, and for anyone building Python tooling — linters, formatters, code-mods, static analyzers, or obfuscators — where reading and transforming the AST is the core technique.
When Python runs your code, it first tokenizes the source, then parses those tokens into an AST: a tree in which every construct — a module, function definition, loop, if-statement, function call, or literal — becomes a typed node with named fields and child nodes. This tree is the structured, unambiguous form of your program, which is why real tooling operates on it instead of manipulating raw text with regular expressions.
Seeing the tree makes abstract behavior concrete. You can watch how operator precedence nests a BinOp, how a list comprehension expands into its component nodes, how default arguments and decorators attach to a FunctionDef, or how an assignment splits into targets and a value. It's one of the fastest ways to build an accurate mental model of Python's grammar.
The same structure is available in Python itself through the built-in ast module: ast.parse(source) returns the tree, ast.dump() prints it, ast.walk() and ast.NodeVisitor let you traverse it, and ast.NodeTransformer lets you rewrite it. This viewer is essentially an interactive, no-setup front end to ast.parse — handy for prototyping a visitor or confirming what a snippet compiles to before you write the traversal code.
AST generation runs client-side in your browser, so you get an immediate result the moment you paste your code.
Want the flow instead of the tree? Turn the same code into a diagram with the Python code-to-flowchart generator — it reads this AST to draw if/loop/match/try branches and a control-flow graph.
Frequently Asked Questions
Explore Other Tools
Python to EXE Online
Paste a Python script and download a standalone Windows .exe — a real PyInstaller build, no install. Plus a command & GitHub Actions generator for macOS/Linux and dependencies.
cURL to Python Converter
Paste any curl command and instantly get clean Python code for requests, httpx, or aiohttp.
Ruff Linter & Formatter
Run Ruff online — the fast Rust linter & formatter that replaces Flake8, isort and Black. Free, no install, runs in your browser.
Ruff Playground
A deep Ruff playground: inspect the AST and token stream Ruff parses, its formatter IR, and live ruff check diagnostics, while editing the Ruff config and sharing a link that reopens your exact setup.