{"id":768,"library":"google-pasta","title":"google-pasta","description":"google-pasta is an AST-based Python refactoring library (version 0.2.0). It aims to enable robust Python source code refactoring through Abstract Syntax Tree (AST) modifications, useful for tasks like renaming modules, rewriting import statements, enforcing code style, or safely migrating code between APIs. The library is currently marked as 'Pre-Alpha' on PyPI and has a slow release cadence, with the last update in March 2020.","status":"maintenance","version":"0.2.0","language":"python","source_language":"en","source_url":"https://github.com/google/pasta","tags":["AST","refactoring","code transformation","static analysis"],"install":[{"cmd":"pip install google-pasta","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"parse","correct":"import pasta\nsrc = 'def foo(): pass'\nast = pasta.parse(src)"},{"symbol":"dump","correct":"import pasta\nsrc = 'def foo(): pass'\nast = pasta.parse(src)\nreconstructed_src = pasta.dump(ast)"}],"quickstart":{"code":"import pasta\n\n# Original source code string\noriginal_code = \"\"\"\ndef greet(name):\n    print(f\"Hello, {name}!\")\n\ngreet(\"World\")\n\"\"\"\n\n# Parse the source code into an AST\nast_tree = pasta.parse(original_code)\n\n# (Optional) Modify the AST here, for example, renaming a function\n# For simplicity, we're just parsing and dumping to demonstrate symmetry\n\n# Dump the AST back into source code\nreconstructed_code = pasta.dump(ast_tree)\n\n# Verify symmetry (as per pasta's design goals)\nassert original_code == reconstructed_code\n\nprint(\"Original Code:\\n\" + original_code)\nprint(\"Reconstructed Code:\\n\" + reconstructed_code)\nprint(f\"Code matches after parse and dump: {original_code == reconstructed_code}\")","lang":"python","description":"This quickstart demonstrates the core functionality of `google-pasta`: parsing Python source code into an AST and then dumping it back into a string. A key design goal is 'symmetry', meaning `pasta.dump(pasta.parse(src))` should equal the original source code."},"warnings":[{"fix":"Ensure your environment's Python version matches the target code's Python version. Be cautious with newer Python syntax features (e.g., f-strings) if `pasta`'s development predates their full support.","message":"The library operates under the assumption that the Python version for which the code is written is the same as the Python version running `pasta`. This is due to its reliance on the built-in `ast.parse` module, which can have version-specific behaviors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Be aware of this limitation when designing refactoring tools. For transformations requiring indentation changes, post-processing with a linter/formatter might be necessary.","message":"Changing indentation levels of code blocks is not directly supported, which can limit certain refactoring operations like extracting methods.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Test `pasta` thoroughly with codebases containing these unsupported features before relying on it for critical refactoring tasks.","message":"Some Python features, such as the `global` keyword, are not fully supported, which can lead to incorrect transformations or parsing errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use with caution and thorough testing. Do not rely on it for mission-critical applications without extensive validation of its output.","message":"The project's PyPI status is '2 - Pre-Alpha', indicating it is still experimental and not considered stable or production-ready by its maintainers.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Verify functionality with your specific Python version and syntax before use. Consider contributing to the project if you encounter issues or require newer feature support.","message":"Development is slow or stalled. The last PyPI release (0.2.0) was in March 2020, and the last reported code push activity was around late 2020. Open issues exist for modern Python syntax (e.g., f-strings parsing failures, Python 3.10 support), suggesting potential compatibility problems with newer Python versions.","severity":"gotcha","affected_versions":"Python 3.8+ (potentially)"}],"env_vars":null,"last_verified":"2026-05-12T18:49:33.037Z","next_check":"2026-06-27T00:00:00.000Z","problems":[{"fix":"Avoid using `google-pasta` for code containing `async/await` syntax, or manually refactor such code. The library's development is slow, and full support for newer Python features may not be available in older versions.","cause":"The `google-pasta` library, particularly version 0.2.0, has limitations in parsing modern Python syntax, including `async/await` keywords, leading to an `AnnotationError` when encountering such constructs.","error":"pasta.base.annotate.AnnotationError: Expected 'return' but found 'async'"},{"fix":"Install the library using pip: `pip install google-pasta`.","cause":"This error occurs when the `google-pasta` library is not installed or not accessible in the current Python environment.","error":"ModuleNotFoundError: No module named 'google.pasta'"},{"fix":"Manually adjust indentation levels in your code if refactoring requires such changes, as `google-pasta` is not designed to handle this operation.","cause":"This is a known limitation of the `google-pasta` library, meaning it cannot automatically adjust or refactor code blocks by changing their indentation.","error":"Changing the indentation level of a block of code is not supported."},{"fix":"Refactor f-strings that exhibit this specific pattern to use alternative formatting methods or simpler f-string expressions that avoid the problematic syntax.","cause":"The `google-pasta` library may encounter parsing issues with f-strings that contain an equals sign (`=`) at the end of a field, indicating a limitation with specific f-string syntax.","error":"Failure to parse f-strings when field has = at the end."}],"ecosystem":"pypi","meta_description":null,"install_score":100,"install_tag":"verified","quickstart_score":30,"quickstart_tag":"draft","pypi_latest":"0.2.0","cli_name":"","cli_version":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","installed_version":null,"pypi_latest":"0.2.0","is_stale":null,"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"18.3M"},{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.1,"disk_size":"18.3M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.6,"import_time_s":0.01,"mem_mb":1.1,"disk_size":"19M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.01,"mem_mb":1.1,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.3,"disk_size":"20.3M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.04,"mem_mb":1.3,"disk_size":"20.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.6,"import_time_s":0.03,"mem_mb":1.3,"disk_size":"21M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.3,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":0.9,"disk_size":"12.2M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":0.9,"disk_size":"12.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.7,"import_time_s":0.03,"mem_mb":0.9,"disk_size":"13M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":0.9,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"11.9M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1.2,"disk_size":"11.8M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.6,"import_time_s":0.03,"mem_mb":1,"disk_size":"12M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.03,"mem_mb":1,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"17.8M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"17.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":null,"install_time_s":1.8,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"18M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"google-pasta","exit_code":0,"wheel_type":null,"failure_reason":null,"import_side_effects":null,"install_time_s":null,"import_time_s":0.02,"mem_mb":1.4,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-24","tag":"draft","tag_description":"notable failures across runtimes","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}