Registry / serialization / ast-decompiler

ast-decompiler

JSON →
library0.8.0pypypi✓ verified 85d ago

Python module to decompile AST (Abstract Syntax Tree) back into Python source code. Current version 0.8.0, requires Python >=3.8. Releases are occasional, primarily maintained by the author.

pip install ast-decompiler
INSTALL
IMPORT
SIG · AST-DECOMPILER
A
ast-decompiler
serializationpythonv0.8.0
Install
1.5s avg
Import
34ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.034s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.034s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

decompile
from ast_decompiler import decompile
Library is imported as ast_decompiler, not ast-decompiler or astdecompiler.

Parses Python code into AST using the standard library, then decompiles it back to Python source code using ast_decompiler.

import ast from ast_decompiler import decompile code = """def hello(name): return f'Hello, {name}!' """ tree = ast.parse(code) reconstructed = decompile(tree) print(reconstructed) # Output: def hello(name): # return f'Hello, {name}!'
ast-decompiler --version
Debug
Known issues
gotchaThe import path is `ast_decompiler`, not `ast-decompiler` (with hyphen). Using `import ast-decompiler` will cause a syntax error.
fix
Use `from ast_decompiler import decompile` or `import ast_decompiler`.
affects: all
gotchadecompile() expects an AST node, not a string. Passing a string will raise AttributeError or TypeError.
fix
Always parse code with ast.parse() first: tree = ast.parse(code); decompile(tree).
affects: all
deprecatedThe old function name `decompile_to_code` may exist in very early versions or forks. It is deprecated in favor of `decompile`.
fix
Use `decompile` instead.
affects: < 0.6.0 (if applicable)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ast_decompiler'
You have not installed the package, or you installed it under a different virtual environment.
fix
Run `pip install ast-decompiler`, ensure you are in the correct virtual environment or use `pip3` if needed.
AttributeError: module 'ast_decompiler' has no attribute 'decompile_to_code'
You are using an outdated function name. The function was renamed or removed.
fix
Use `decompile` instead: `from ast_decompiler import decompile`.
AttributeError: 'str' object has no attribute 'body'
You passed a string to decompile() instead of an AST node.
fix
Parse the string first with `ast.parse()`: `tree = ast.parse(code)`, then `decompile(tree)`.
Upgrade
Version history
0.8.0latest on PyPI · released May 17, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
21 hits · last 30 days
node
18
Amazon
1
OpenAI (training)
1
Resources
ast-decompiler — pip install ast-decompiler · libregistry