ast

Stdlib — IntrospectionPython 2.6+Expert

Parse Python source into an Abstract Syntax Tree

Quick Info

Documentation
Official Docs
Python Version
2.6+
Dependencies
None — Python Standard Library
Install
Included with Python

Learn by Difficulty

Quick Example

python
import ast

code = "x = [i**2 for i in range(10) if i % 2 == 0]"
tree = ast.parse(code)
print(ast.dump(tree, indent=2))

The ast module is part of Python's standard library. Parse Python source into an Abstract Syntax Tree.

Try in Playground

Tags

stdlibintrospectionmetaprogrammingparsing

Related Items