{"id":23281,"library":"ast-decompiler","title":"AST Decompiler","description":"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.","status":"active","version":"0.8.0","language":"python","source_language":"en","source_url":"https://github.com/lextm/ast-decompiler","tags":["ast","decompiler","code-generation"],"install":[{"cmd":"pip install ast-decompiler","lang":"bash","label":"pip install"}],"dependencies":[],"imports":[{"note":"Library is imported as ast_decompiler, not ast-decompiler or astdecompiler.","symbol":"decompile","correct":"from ast_decompiler import decompile"}],"quickstart":{"code":"import ast\nfrom ast_decompiler import decompile\n\ncode = \"\"\"def hello(name):\n    return f'Hello, {name}!'\n\"\"\"\ntree = ast.parse(code)\nreconstructed = decompile(tree)\nprint(reconstructed)\n# Output: def hello(name):\n#     return f'Hello, {name}!'","lang":"python","description":"Parses Python code into AST using the standard library, then decompiles it back to Python source code using ast_decompiler."},"warnings":[{"fix":"Use `from ast_decompiler import decompile` or `import ast_decompiler`.","message":"The import path is `ast_decompiler`, not `ast-decompiler` (with hyphen). Using `import ast-decompiler` will cause a syntax error.","severity":"gotcha","affected_versions":"all"},{"fix":"Always parse code with ast.parse() first: tree = ast.parse(code); decompile(tree).","message":"decompile() expects an AST node, not a string. Passing a string will raise AttributeError or TypeError.","severity":"gotcha","affected_versions":"all"},{"fix":"Use `decompile` instead.","message":"The old function name `decompile_to_code` may exist in very early versions or forks. It is deprecated in favor of `decompile`.","severity":"deprecated","affected_versions":"< 0.6.0 (if applicable)"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run `pip install ast-decompiler`, ensure you are in the correct virtual environment or use `pip3` if needed.","cause":"You have not installed the package, or you installed it under a different virtual environment.","error":"ModuleNotFoundError: No module named 'ast_decompiler'"},{"fix":"Use `decompile` instead: `from ast_decompiler import decompile`.","cause":"You are using an outdated function name. The function was renamed or removed.","error":"AttributeError: module 'ast_decompiler' has no attribute 'decompile_to_code'"},{"fix":"Parse the string first with `ast.parse()`: `tree = ast.parse(code)`, then `decompile(tree)`.","cause":"You passed a string to decompile() instead of an AST node.","error":"AttributeError: 'str' object has no attribute 'body'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}