berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
810 stars 102 forks source link

============================= astor -- AST observe/rewrite

:PyPI: https://pypi.org/project/astor/ :Documentation: https://astor.readthedocs.io :Source: https://github.com/berkerpeksag/astor :License: 3-clause BSD :Build status: .. image:: https://secure.travis-ci.org/berkerpeksag/astor.svg :alt: Travis CI :target: https://travis-ci.org/berkerpeksag/astor/

astor is designed to allow easy manipulation of Python source via the AST.

There are some other similar libraries, but astor focuses on the following areas:

.. [1] The decompilation back to Python is based on code originally written by Armin Ronacher. Armin's code was well-structured, but failed on some obscure corner cases of the Python language (and even more corner cases when the AST changed on different versions of Python), and its output arguably had cosmetic issues -- for example, it produced parentheses even in some cases where they were not needed, to avoid having to reason about precedence.

Other derivatives of Armin's code are floating around, and typically
have fixes for a few corner cases that happened to be noticed by the
maintainers, but most of them have not been tested as thoroughly as
astor.  One exception may be the version of codegen
`maintained at github by CensoredUsername`__.  This has been tested
to work properly on Python 2.7 using astor's test suite, and, as it
is a single source file, it may be easier to drop into some applications
that do not require astor's other features or Python 3.x compatibility.

__ https://github.com/CensoredUsername/codegen