astunparse
An AST unparser for Python
What it is and what it does
astunparse is a library that converts Python AST (abstract syntax tree) objects back into readable source code and provides a pretty-printed dump of AST structure. It factors out the unparse utility from Python's standard library, making it available as a standalone package.
The library is built on mature, core-maintained code from the Python source distribution and roundtrips much of the standard library. It depends only on wheel and six, making installation straightforward. However, the project is abandoned—last updated 2019-12-22—so it will not receive updates for newer Python versions or syntax features.
Use it for:
- Recover source code from compiled or introspected AST objects for debugging or code analysis.
- Generate readable Python code from programmatically constructed AST trees in code generation tools.
- Pretty-print AST structure for educational purposes or to understand how Python parses code.
- Roundtrip Python source through parse and unparse cycles to verify AST fidelity in testing.
- Implement metaprogramming tools that need to display or manipulate AST as human-readable code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Converts Python abstract syntax trees (ASTs) back into source code and provides pretty-printed AST dumps.
Yes, if you work with Python versions supported at the last release (2019-12-22) and need reliable AST-to-source conversion. The code is stable and well-tested. No if you require support for newer Python versions—the abandoned status means no updates are coming. Consider alternatives if you need active maintenance.
Install
astunparse on PyPI
pip
pip install astunparseuv
uv add astunparsepoetry
poetry add astunparseInstalling astunparse
Before you install
Low friction install with minimal dependencies (wheel, six). Maintenance is abandoned—last release was 2019-12-22 and last commit 2023-08-18—so expect no active bug fixes or support for newer Python versions.
License in practice
BSD license is permissive; you can use, modify, and distribute this code with minimal restrictions, though you must retain the license notice.
Quickstart
import ast
import astunparse
code = "x = 1 + 2"
tree = ast.parse(code)
print(astunparse.unparse(tree))
print(astunparse.dump(tree))
Abandoned since 2019-12-22; no updates for Python versions beyond those listed in classifiers. May not handle newer syntax features.
Verify before relying
- Compatibility with Python versions released after 2019-12-22 and AST node types introduced after that date.
- Whether roundtrip fidelity is maintained for Python constructs added after the last release.
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — wheel, six |
| Maintenance | abandoned — 2,427 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 14,034,836/month — #1,251 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: astunparse-1.6.3-py2.py3-none-any.whl
Keywords: astunparse
Tags
More Code Generators packages
Proto Plus wraps protocol buffers to provide…
permissive · top 1,000 on PyPI
CythonCython is a source code translator that…
permissive · top 1,000 on PyPI
asttokensAnnotates Python abstract syntax trees with the…
permissive · top 1,000 on PyPI
beartypeBeartype is a runtime type checker that…
permissive · top 1,000 on PyPI
llvmlitellvmlite provides a lightweight Python binding…
permissive · top 1,000 on PyPI
astorastor converts Python abstract syntax trees…
permissive · top 5,000 on PyPI
ast-decompilerConverts Python abstract syntax trees (ASTs)…
permissive · top 15,000 on PyPI
ast-commentsExtends Python's built-in `ast` module to…
permissive · top 15,000 on PyPI
astprettyPretty-print Python abstract syntax trees (AST)…
permissive · top 15,000 on PyPI
google-pastaParse Python source code into an AST, modify…
permissive · top 1,000 on PyPI
luaparserParses Lua source code into an abstract syntax…
permissive · top 15,000 on PyPI
gastProvides a unified Abstract Syntax Tree…
permissive · top 5,000 on PyPI
libcstlibcst parses Python source code into a…
permissive · top 1,000 on PyPI
benigetBeniget performs compile-time analysis on…
permissive · top 15,000 on PyPI