astpretty is a Python library designed to pretty-print the Abstract Syntax Tree (AST) generated by Python's standard library `ast.parse` function. It offers a more readable, indented, and detailed representation of AST nodes compared to the built-in `ast.dump`, making it useful for debugging and understanding code structure. The current version is 3.0.0, released in May 2022, requiring Python 3.8+. It's a stable, focused utility with infrequent but significant updates.
pip install astprettyVerified import paths — ran on the pinned version, not inferred.
This example demonstrates parsing a simple Python code snippet into an AST using the standard `ast` module and then using `astpretty.pprint` to display its structured, human-readable representation. You can also use `astpretty.pformat` to get the pretty-printed string instead of printing directly to stdout.
Upgrade your Python environment to 3.8 or newer. For Python 2, use `astpretty < 2.0.0` (not recommended for new development).
For less verbosity, use `astpretty.pprint(node, show_offsets=False)`. For Python 3.9+, consider `ast.dump(node, indent=...)` if a simpler, indented string is sufficient. `astpretty` generally offers more detailed AST information.
Always use `import ast` and `ast.parse(your_code_string)` to obtain an AST node, then pass that node to `astpretty` functions.
No dependency data recorded yet.