Skip to main content

Read/rewrite/write Python ASTs

Project description

PyPI:

https://pypi.python.org/pypi/astor

Documentation:

http://astor.rtfd.org/

Source:

https://github.com/berkerpeksag/astor

License:

3-clause BSD

Build status:
Travis CI

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:

  • Round-trip an AST back to Python [1]:

    • Modified AST doesn’t need linenumbers, ctx, etc. or otherwise be directly compileable for the round-trip to work.

    • Easy to read generated code as, well, code

    • Can round-trip two different source trees to compare for functional differences, using the astor.rtrip tool (for example, after PEP8 edits).

  • Dump pretty-printing of AST

    • Harder to read than round-tripped code, but more accurate to figure out what is going on.

    • Easier to read than dump from built-in AST module

  • Non-recursive treewalk

    • Sometimes you want a recursive treewalk (and astor supports that, starting at any node on the tree), but sometimes you don’t need to do that. astor doesn’t require you to explicitly visit sub-nodes unless you want to:

    • You can add code that executes before a node’s children are visited, and/or

    • You can add code that executes after a node’s children are visited, and/or

    • You can add code that executes and keeps the node’s children from being visited (and optionally visit them yourself via a recursive call)

    • Write functions to access the tree based on object names and/or attribute names

    • Enjoy easy access to parent node(s) for tree rewriting

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

astor-0.6.1.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

astor-0.6.1-py2.py3-none-any.whl (26.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file astor-0.6.1.tar.gz.

File metadata

  • Download URL: astor-0.6.1.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for astor-0.6.1.tar.gz
Algorithm Hash digest
SHA256 7b9bf42bf4554407f7698d55960dc6bc4c86e1f4edb4bf015d54fd214ef4fe73
MD5 46c30a330e0d3edf6b1713faf7bb9e49
BLAKE2b-256 cfc20506e7721f8d8eccc8c1bf5ff727176e65d9c6b66f02602b6dd7ba433476

See more details on using hashes here.

File details

Details for the file astor-0.6.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for astor-0.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e4911a6d2d5dee5c54e99ed549ccbcf07dc5d63cc8024ccc7f89d090a94aa274
MD5 12181302f3c964a44a7b26690933a229
BLAKE2b-256 01206cc2d11ee314b1b62ebbd07afb811c72d95a3274f1ea246e2db71b57b2dd

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