Parso: A Python Parser
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.
Warnings
- breaking Parso dropped support for Python 2.7, 3.4, and 3.5 in version 0.8.0.
- deprecated The 'lib2to3' module is deprecated since Python 3.10 and may be removed in future versions. Parso is a recommended alternative.
- 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.
- 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.
Install
-
pip install parso
Imports
- parse
from parso import parse
Quickstart
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())