Green Tree Snakes - the missing Python AST docs

Abstract Syntax Trees, ASTs, are a powerful feature of Python. You can write programs that inspect and modify Python code, after the syntax has been parsed, but before it gets compiled to byte code. That opens up a world of possibilities for introspection, testing, and mischief.

The official documentation for the ast module is good, but somewhat brief. Green Tree Snakes is more like a field guide (or should that be forest guide?) for working with ASTs. To contribute to the guide, see the source repository.

Contents:

See also

Python AST explorer
Web-based AST viewer: paste some code in and see the AST
Thonny
A Python IDE with AST explorer built in (Main menu => View => AST)
showast
An IPython extension to show ASTs in Jupyter notebooks
Instrumenting the AST
Using AST tools to assess code coverage

Indices and tables