Need help with astunparse?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

172 Stars 42 Forks Other 86 Commits 22 Opened issues


An AST unparser for Python

Services available


Need anything else?

Contributors list


AST Unparser

.. image:: :target:

.. image:: :target:

.. image:: :target:

An AST unparser for Python.

This is a factored out version of

found in the Python source distribution; under Demo/parser in Python 2 and under Tools/parser in Python 3.

Basic example::

import inspect
import ast
import astunparse

get back the source code


get a pretty-printed dump of the AST


This library is single-source compatible with Python 2.6 through Python 3.5. It is authored by the Python core developers; I have simply merged the Python 2.7 and the Python 3.5 source and test suites, and added a wrapper. This factoring out is to provide a library implementation that supports both versions.

Added to this is a pretty-printing

utility function.

The test suite both runs specific tests and also roundtrips much of the standard library.

Extensions and Alternatives

Similar projects include:

* codegen_
* astor_
* astmonkey_
* astprint_

None of these roundtrip much of the standard library and fail several of the basic tests in the

test suite.

This library uses mature and core maintained code instead of trying to patch existing libraries. The

and the
modules are under the PSF license.

Extensions include:

* typed-astunparse: extends astunparse to support type annotations.
  • Documentation:


  • unparses Python AST.
  • pretty-prints AST.

.. _codegen: .. _astor: .. _astmonkey: .. _astprint:

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.