Skip to main content

human-oriented ast parser/unparser

Project description

package version from PyPI build status from Travis CI build status from AppVeyor grade from Codacy test coverage from Codecov license

Attempt at a human-oriented abstract syntax tree (AST) parser/unparser for Python 3.

This package provides new AST node types which inherit from nodes in typed_ast.ast3 module. Additionally, it provides implementation of parser and unparser for the extended ASTs.

Simple example of how to use this package:

from horast import parse, unparse

tree = parse("""a = 1  # a equals one after this""")
# this will print the code with original comment

More examples in examples.ipynb.

technical details

Parser is based on built-in tokenize module and typed_ast.ast3.parse() function.

Unparser is essentially an extension of Unparser class from typed_astunparse package.

Nodes provided and handled by horast are listed below.


Full line as well as end-of-line comments are parsed/unparsed correctly when they are outside of multi-line expressions.

Currently, handling of comments within multi-line expressions is implemented only partially.


To do.


CPython >= 3.4.

Python libraries as specified in requirements.txt.

Building and running tests additionally requires packages listed in test_requirements.txt.

Project details

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
horast-0.2.4-py3-none-any.whl (16.2 kB) Copy SHA256 hash SHA256 Wheel py3
horast-0.2.4.tar.gz (21.6 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page