Skip to main content

An AST unparser for Python

Project description

============
AST Unparser
============

.. image:: https://badge.fury.io/py/astunparse.png
:target: http://badge.fury.io/py/astunparse

.. image:: https://travis-ci.org/simonpercivall/astunparse.png?branch=master
:target: https://travis-ci.org/simonpercivall/astunparse

.. image:: https://pypip.in/d/astunparse/badge.png
:target: https://crate.io/packages/astunparse?version=latest

An AST unparser for Python.

This is a factored out version of `unparse` 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
astunparse.unparse(ast.parse(inspect.getsource(ast)))

# get a pretty-printed dump of the AST
astunparse.dump(ast.parse(inspect.getsource(ast)))


This library is single-source compatible with Python 2.6 through Python 3.4. It
is authored by the Python core developers; I have simply merged the Python 2.7
and the Python 3.4 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 `dump` utility function.

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

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_unparse` test suite.

This library uses mature and core maintained code instead of trying to patch
existing libraries. The `unparse` and the `test_unparse` modules
are under the PSF license.

* Documentation: http://astunparse.rtfd.org.

Features
--------

* unparses Python AST.
* pretty-prints AST.


.. _codegen: https://github.com/andreif/codegen
.. _astor: https://github.com/berkerpeksag/astor
.. _astmonkey: https://github.com/konradhalas/astmonkey
.. _astprint: https://github.com/Manticore/astprint


=========
Changelog
=========

Here's the recent changes to AST Unparser.

.. changelog::
:version: 1.2.0
:released: 2014-04-03

.. change::
:tags: general

Now compatible with Python 2.6 through Python 3.4.

.. change::
:tags: general

A new function :func:`dump` is added to return a pretty-printed version
of the AST. It's also available when running `python -m astunparse` as
the `--dump` argument.


.. changelog::
:version: 1.1.0
:released: 2014-04-01

.. change::
:tags: general

:func:`unparse` will return the source code for an AST. It is pretty
feature-complete, and round-trips the stdlib, and is compatible with
Python 2.7 and Python 3.4.

Running `python -m astunparse` will print the round-tripped source for
any python files given as argument.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astunparse-1.2.0.tar.gz (12.0 kB view details)

Uploaded Source

File details

Details for the file astunparse-1.2.0.tar.gz.

File metadata

  • Download URL: astunparse-1.2.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for astunparse-1.2.0.tar.gz
Algorithm Hash digest
SHA256 38824c348888b9c5490ac86a50a29484a4a3b3642a0c13328dd0c988f6f3d3f5
MD5 335d7b806a64e6bcb4111e5936eab479
BLAKE2b-256 6c315f707422451033ca303efc0a77cddeff5898d0854dfd754a74c6f647798b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page