astpretty
Pretty print the output of python stdlib `ast.parse`.
What it is and what it does
astpretty formats Python abstract syntax trees into indented, readable output that makes it easy to inspect the structure of parsed code. It wraps stdlib ast.parse results and provides two main functions: pprint() to display a tree directly, and pformat() to return it as a string. You can control indentation style and choose whether to include line/column offset metadata, which ast.dump does not easily allow.
The package is a thin, zero-dependency utility designed for developers debugging or analyzing Python code at the AST level—particularly useful in linters, code generators, and syntax analysis tools. It also supports typed-ast for type-annotated parsing when installed as an optional extra.
Use it for:
- Debug Python code by inspecting its AST structure during linter or code-analysis tool development.
- Visualize parsed syntax in REPL sessions or notebooks to understand how Python parses specific code patterns.
- Generate readable AST dumps in test output or documentation to verify code transformation logic.
- Inspect type-annotated code structures when using typed-ast for Python 2 or type-comment parsing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pretty-print Python abstract syntax trees (AST) from stdlib ast.parse in a readable, hierarchical format with optional line/column offsets, as a more legible alternative to ast.dump.
Yes. astpretty is a lightweight, actively maintained utility with no dependencies, permissive licensing, and a clear single purpose: making AST inspection readable. Install it if you work with Python's ast module and want output that doesn't collapse into a single unreadable line. No security concerns, no friction.
Install
astpretty on PyPI
pip
pip install astprettyuv
uv add astprettypoetry
poetry add astprettyInstalling astpretty
Before you install
Low friction: pure Python wheel with no runtime dependencies. Actively maintained as of 2026-07-15 with 200 repository stars.
License in practice
MIT license (permissive) places no restrictions on use, modification, or distribution.
Quickstart
pip install astpretty
import ast
import astpretty
node = ast.parse('if x == y: y += 4').body[0]
astpretty.pprint(node)
Verify before relying
- Whether typed-ast support (optional via extras) remains actively maintained or tested.
- Current test coverage and whether the package handles edge cases in modern Python AST structures.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 1,551 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 552,844/month — #6,041 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: astpretty-3.0.0-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
gastProvides a unified Abstract Syntax Tree…
permissive · top 5,000 on PyPI
objprintobjprint provides functions to print Python…
permissive · top 5,000 on PyPI
astunparseConverts Python abstract syntax trees (ASTs)…
permissive · top 5,000 on PyPI
ast-decompilerConverts Python abstract syntax trees (ASTs)…
permissive · top 15,000 on PyPI
typed-astProvides Python 2.7 and Python 3 AST parsers…
permissive · top 5,000 on PyPI
google-pastaParse Python source code into an AST, modify…
permissive · top 1,000 on PyPI
ast-commentsExtends Python's built-in `ast` module to…
permissive · top 15,000 on PyPI
stdlibsProvides a static listing of all known modules…
permissive · top 5,000 on PyPI
astorastor converts Python abstract syntax trees…
permissive · top 5,000 on PyPI
luaparserParses Lua source code into an abstract syntax…
permissive · top 15,000 on PyPI