In order to traverse the tree, the python compiler package provides a visitor interface. Put simply, you provide a class which implements methods which correspond to AST nodes in the tree (e.g. visitFunction(), visitClass(), visitCallFunc()). The compiler module then walks over the AST tree, invoking the relevant methods of your class in order.