Live coding environment to develop intuition about how Python source code compiles to ASTs and bytecodes
JavaScript Python CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
TODOs.txt first real version Dec 6, 2013
funcall torture screenshot.png
jquery-1.10.2.min.js ahh Apr 1, 2014
py-workbench.css MASSIV Dec 19, 2013
py-workbench.js minor Feb 8, 2014 booya Dec 14, 2013

Python Compiler Workbench


This is a live coding environment to help you develop intuitions about how Python source code compiles to ASTs and bytecodes. As you type in code, it gets compiled to AST and bytecode formats, and the visualization updates instantaneously.

Watch the 1.5-minute YouTube demo.


  1. Download GraphViz and install it.
  2. Install two Python packages: bottle and pydot.

One way to install is:

easy_install pip
pip install bottle
pip install pydot


  1. Run python to start the server.
  2. Visit http://localhost:8080/index.html

(tested with Python 2.7 on Mac OS X so far)

Why did I create this project?

Because it was the fastest and most effective way for me to learn about Python ASTs.

The official docs aren't that helpful for gaining intuitions about what real ASTs look like. They are more of a reference guide, not a tutorial. So I figured that the best tutorial would be to create an environment where I could easily enter in any piece of Python code and see what it compiled into.

For instance, I wanted to see what a chain of if-elif-else blocks looked like in the AST, so I just typed in a simple example:


Low and behold, it compiles into a series of nested if-else blocks!

On a meta level, the process of building this tool itself -- especially writing the code to transform ASTs into the GraphViz format for visualization -- gave me even better intuitions for how AST nodes are structured.

So all in all, it's been a very efficient and fun way for me to learn :) And if this project helps you learn as well, then even better!