skillfed

astpretty

Pretty print the output of python stdlib `ast.parse`.

astpretty v3.0.0 552.8K downloads/30d#6,041 on PyPI200
Permissive license MIT Active released

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 astpretty

uv

uv add astpretty

poetry

poetry add astpretty

Installing 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

License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPy

Tags

ast pretty printpython ast visualizationast.dump alternativereadable ast outputast formatting tooldebug python syntax trees
ast-inspectiondebugging-toolcode-analysis

More Software Development packages