skillfed

astunparse

An AST unparser for Python

astunparse v1.6.3 14.0M downloads/30d#1,251 on PyPI230
Permissive license BSD Abandoned released

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 astunparse

uv

uv add astunparse

poetry

poetry add astunparse

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseNatural Language :: EnglishProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Topic :: Software Development :: Code Generators

Tags

ast to source codeunparse python astast pretty printpython code generation from astast roundtripdump ast treeast serialization
ast-manipulationcode-generationlegacy

More Code Generators packages