Parso: A Python Parser

raw JSON →
0.8.6 verified Tue May 12 auth: no python install: verified quickstart: stale

Parso is a Python parser that supports error recovery and round-trip parsing for different Python versions. It is currently at version 0.8.6, released on February 9, 2026, and follows a regular release cadence with updates approximately every 6 months.

pip install parso
error ModuleNotFoundError: No module named 'parso'
cause The 'parso' library has not been installed in the Python environment where the code is being executed.
fix
Install the 'parso' package using pip: pip install parso
error SyntaxError: invalid syntax
cause This error message is typically returned by `parso` when the code it attempts to parse contains actual Python syntax errors, or when `parso` is used with a Python version that doesn't match the syntax of the provided code.
fix
Correct the syntax of the Python code being parsed. If the code uses modern Python features, ensure your installed 'parso' version is up-to-date (pip install --upgrade parso) and explicitly specify the Python version using the version parameter in parso.parse() or parso.load_grammar() (e.g., parso.parse('code', version='3.9')).
error ImportError: cannot import name 'Parser'
cause Users attempting to directly import a class named 'Parser' from the 'parso' package or its submodules, which is not part of the public API or has a different internal name.
fix
Instead of directly importing Parser, use the public API functions like parso.parse() for simple parsing or parso.load_grammar().parse() for more controlled parsing with a specific grammar.
error KeyError: ReservedString(})
cause This error can occur when `parso` encounters complex or malformed string literals, especially f-strings or raw strings with unescaped curly braces, that it struggles to tokenize or parse correctly.
fix
Review the string literal in the code for proper escaping of special characters like curly braces in f-strings or backslashes in raw strings. Ensure the string is well-formed according to Python's grammar. Updating 'parso' to the latest version might also resolve issues with newer string syntaxes.
breaking Parso dropped support for Python 2.7, 3.4, and 3.5 in version 0.8.0.
fix Upgrade to a supported Python version (3.6 or later).
deprecated The 'lib2to3' module is deprecated since Python 3.10 and may be removed in future versions. Parso is a recommended alternative.
fix Use Parso for parsing tasks instead of 'lib2to3'.
gotcha A `SyntaxError: invalid syntax` occurred because a single-quoted string literal (`'...'`) contained an unescaped single quote, prematurely terminating the string and leading to invalid syntax at the subsequent characters.
fix To resolve, escape the internal single quotes (e.g., `\'World\'`) or enclose the entire string in double quotes (`"..."`) or triple quotes (`'''...'''`) to allow internal single quotes without escaping.
breaking A `SyntaxError` occurred in the test script due to an unescaped quote within a string literal used for code generation, preventing the script from running. This is a fundamental Python syntax issue with string definition.
fix Ensure string literals in test scripts are correctly escaped (e.g., `\'World\'`) or use triple quotes (e.g., `'''... 'World' ...'''`) to define multi-line code snippets that contain single or double quotes.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.10s 18.4M
3.10 slim (glibc) - - 0.07s 19M
3.11 alpine (musl) - - 0.15s 20.4M
3.11 slim (glibc) - - 0.13s 21M
3.12 alpine (musl) - - 0.13s 12.3M
3.12 slim (glibc) - - 0.12s 13M
3.13 alpine (musl) - - 0.12s 11.9M
3.13 slim (glibc) - - 0.10s 12M
3.9 alpine (musl) - - 0.12s 17.9M
3.9 slim (glibc) - - 0.07s 18M

This example demonstrates how to parse a simple Python function definition and call using Parso.

import parso

code = 'def greet(name):\n    return f"Hello, {name}!"\n\ngreet('World')'

# Parse the code
module = parso.parse(code, version='3.9')

# Access the root node
root_node = module.get_root_node()

# Print the parsed code
print(root_node.get_code())