PARSO(1) parso PARSO(1) (NAME) python-parso - parso v0.8.7. ( <>) Parso (error recovery) (round-trip parsing) ( ) . Parso . Parso jedi . jedi . Parso API . : >>> import parso >>> module = parso.parse('hello + 1', version="3.9") >>> expr = module.children[0] >>> expr PythonNode(arith_expr, [, , ]) >>> print(expr.get_code()) hello + 1 >>> name = expr.children[0] >>> name >>> name.end_pos (1, 5) >>> expr.end_pos (1, 9) : >>> grammar = parso.load_grammar() >>> module = grammar.parse('foo +\nbar\ncontinue') >>> error1, error2 = grammar.iter_errors(module) >>> error1.message 'SyntaxError: invalid syntax' >>> error2.message "SyntaxError: 'continue' not properly in loop" (DOCS) (Installation and Configuration) (pip) parso (PyPI) pip : sudo pip install parso git ( master) : sudo pip install -e git+https://github.com/davidhalter/parso.git#egg=parso ( ) parso . setup.py : sudo python setup.py install (Usage) parso . parso.load_grammar() . ( ) parso.Grammar() . <# parser-tree> . parso (parso.parse()): >>> import parso >>> parso.parse('foo + bar') (Loading a Grammar) : parso.load_grammar(*, version: str = None, path: str = None) parso.Grammar . . (Parameters) o version (str ) -- version='3.8'. o path (str ) -- (Grammar methods) : class parso.Grammar(text: str , *, tokenizer, parser=, diff_parser=None) parso.load_grammar() . . (Parameters) text -- BNF . parse(code: str | bytes = None, *, error_recovery=True, path: PathLike | str = None, start_symbol: str = None, cache=False, diff_cache=False, cache_path: PathLike | str = None, file_io: FileIO = None) -> _NodeT . . (Parameters) o code (str ) -- . UnicodeDecodeError . o error_recovery (bool ) -- . . ParseError . o start_symbol (str ) -- ( nonterminal) . error_recovery False . o path (str ) -- . () . o cache (bool ) -- RAM . . pickle ( ~/.cache/parso/). o diff_cache (bool ) -- (diff) . () . . . . o cache_path (bool ) -- parso . . (Returns) parso.tree.NodeOrLeaf <#parso.tree.NodeOrLeaf>. parso.python.tree.Module <#parso.python.tree .Module>. iter_errors(node) parso.tree.NodeOrLeaf <# parso.tree.NodeOrLeaf> parso.normalizer.Issue . / (syntax/indentation) . refactor(base_node, node_to_str_map) (Error Retrieval) parso . : class parso.normalizer.Issue(node, code, message) code . message () . start_pos (line, column). parso . (Utility) parso : parso.parse(code=None, **kwargs) . parso.Grammar.parse() . (Parameters) version (str ) -- parso.load_grammar() . parso.split_lines(string: str , keepends: bool = False) -> list [str ] . str.splitlines() (form feeds) . \n \r\n . : [""] . 2.7 str.splitlines form feed . form feed . parso.python_bytes_to_unicode(source: str | bytes , encoding: str = 'utf-8', errors: str = 'strict') -> str BOM PEP 263 . bytes.decode() . (Parameters) o encoding -- bytes.decode() . o errors -- bytes.decode() . errors 'strict' 'replace' 'ignore' . (Used By) o jedi ( IPython ). o mutmut ( mutation tester) (Parser Tree) parso.Grammar.parse() <#parso.Grammar.parse> . : parso - (1-based) - (0-based) . (1, 0) . (Parser Tree Base Classes) : parso.tree.Leaf parso.tree.BaseNode. class parso.tree.BaseNode(children) Bases: NodeOrLeaf (super class) . (type) . children NodeOrLeaf. property start_pos: Tuple [int , int ] (3, 4). (Return tuple of int) ( ) get_start_pos_of_prefix() start_pos . end_pos . get_start_pos_of_prefix() + 2 + 1 (1, 1) start_pos (1, 2) . (Return tuple of int) ( ) property end_pos: Tuple [int , int ] (3, 4). (Return tuple of int) ( ) get_code(include_prefix=True) . (Parameters) include_prefix -- ( ) . get_leaf_for_position(position, include_prefixes=False) (parso.tree.Leaf) position . (Parameters) o position (tuple ) -- . . o include_prefixes (bool ) -- False position None . (Returns) parso.tree.Leaf position None get_first_leaf() . get_last_leaf() . class parso.tree.Leaf(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: NodeOrLeaf (API) . . value str() . prefix: str str() . property start_pos: Tuple [int , int ] (3, 4). (Return tuple of int) ( ) get_start_pos_of_prefix() start_pos . end_pos . get_start_pos_of_prefix() + 2 + 1 (1, 1) start_pos (1, 2) . (Return tuple of int) ( ) get_first_leaf() . get_last_leaf() . get_code(include_prefix=True) . (Parameters) include_prefix -- ( ) . property end_pos: Tuple [int , int ] (3, 4). (Return tuple of int) ( ) : class parso.tree.NodeOrLeaf Bases: object . type: str . parent: BaseNode <#parso.tree.BaseNode> | None (BaseNode) . None . get_root_node() . . get_next_sibling() . None . get_previous_sibling() . None . get_previous_leaf() . None . get_next_leaf() . None . abstract property start_pos: Tuple [int , int ] (3, 4). (Return tuple of int) ( ) abstract property end_pos: Tuple [int , int ] (3, 4). (Return tuple of int) ( ) abstractmethod get_start_pos_of_prefix() start_pos . end_pos . get_start_pos_of_prefix() + 2 + 1 (1, 1) start_pos (1, 2) . (Return tuple of int) ( ) abstractmethod get_first_leaf() . abstractmethod get_last_leaf() . abstractmethod get_code(include_prefix=True) . (Parameters) include_prefix -- ( ) . search_ancestor(*node_types: str ) -> BaseNode <#parso.tree.BaseNode> | None node_types . None . (Parameters) node_types -- . dump(*, indent: int | str | None = 4) -> str (dump) . . indent ast.dump() . indent (pretty-print) . "" . None . . indent ( "\t") . (Parameters) indent -- . . >>> import parso >>> print(parso.parse("lambda x, y: x + y").dump()) Module([ Lambda([ Keyword('lambda', (1, 0)), Param([ Name('x', (1, 7), prefix=' '), Operator(',', (1, 8)), ]), Param([ Name('y', (1, 10), prefix=' '), ]), Operator(':', (1, 11)), PythonNode('arith_expr', [ Name('x', (1, 13), prefix=' '), Operator('+', (1, 15), prefix=' '), Name('y', (1, 17), prefix=' '), ]), ]), EndMarker('', (1, 18)), ]) (Python Parser Tree) . (imports) . . ( ). Jedi ( ) . parso.tree.NodeOrLeaf.get_code() . (refactor) . >>> from parso import parse >>> parser = parse('import os') >>> module = parser.get_root_node() >>> module Scope Module iter_imports : >>> list(module.iter_imports()) [] (Changes to the Python Grammar) : o Param parameters . parso . . o lambdef lambdef_nocond . class parso.python.tree.DocstringMixin Bases: object type: str children: list [Any ] parent: Any get_doc_node() docstring r'''foo'''. class parso.python.tree.PythonMixin Bases: object . children: list [Any ] get_name_of_position(position) ( ) Name None . class parso.python.tree.PythonLeaf(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: PythonMixin, Leaf get_start_pos_of_prefix() parso.tree.NodeOrLeaf.get_start_pos_of_prefix() . class parso.python.tree.PythonBaseNode(children) Bases: PythonMixin, BaseNode class parso.python.tree.PythonNode(type, children) Bases: PythonMixin, Node class parso.python.tree.PythonErrorNode(children) Bases: PythonMixin, ErrorNode class parso.python.tree.PythonErrorLeaf(token_type, value, start_pos, prefix='') Bases: ErrorLeaf, PythonLeaf class parso.python.tree.EndMarker(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: _LeafWithoutNewlines type: str = 'endmarker' . class parso.python.tree.Newline(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: PythonLeaf NEWLINE ENDMARKER . type: str = 'newline' . class parso.python.tree.Name(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: _LeafWithoutNewlines . () . type: str = 'name' . is_definition(include_setitem=False) True . get_definition(import_name_always=False, include_setitem=False) None . (Parameters) import_name_always -- (import name) . foo from foo import bar . class parso.python.tree.Literal(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: PythonLeaf class parso.python.tree.Number(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: Literal type: str = 'number' . class parso.python.tree.String(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: Literal type: str = 'string' . property string_prefix class parso.python.tree.FStringString(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: PythonLeaf (f-strings) f-string . f-string . type: str = 'fstring_string' . class parso.python.tree.FStringStart(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: PythonLeaf (f-strings) f-string . f-string . type: str = 'fstring_start' . class parso.python.tree.FStringEnd(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: PythonLeaf (f-strings) f-string . f-string . type: str = 'fstring_end' . class parso.python.tree.Operator(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: _LeafWithoutNewlines, _StringComparisonMixin type: str = 'operator' . class parso.python.tree.Keyword(value: str , start_pos: Tuple [int , int ], prefix: str = '') Bases: _LeafWithoutNewlines, _StringComparisonMixin type: str = 'keyword' . class parso.python.tree.Scope(children) Bases: PythonBaseNode, DocstringMixin . (Scope) (lambda) . iter_funcdefs() (generator) funcdef . iter_classdefs() classdef . iter_imports() import_name import_from . get_suite() . class parso.python.tree.Module(children) Bases: Scope (top scope) . . type: str = 'file_input' . get_used_names() Name . . class parso.python.tree.Decorator(children) Bases: PythonBaseNode type: str = 'decorator' . class parso.python.tree.ClassOrFunc(children) Bases: Scope property name Name . get_decorators() (Return type) Decorator class parso.python.tree.Class(children) Bases: ClassOrFunc . type: str = 'classdef' . get_super_arglist() arglist (super classes) . None . class parso.python.tree.Function(children) Bases: ClassOrFunc . : 0. 1. 2. ( ) 3. 5. 4. 6. Node() 3. -> ( ) 4. ( ) type: str = 'funcdef' . get_params() Param() . property name Name . iter_yield_exprs() yield_expr . iter_return_stmts() return_stmt . iter_raise_stmts() raise_stmt raise try-except. is_generator() (Return bool) (generator) . property annotation (test node) -> None . class parso.python.tree.Lambda(children) Bases: Function (Lambdas) . : 0. *. x -2. -1. Node() type: str = 'lambdef' . property name AttributeError . property annotation None . class parso.python.tree.Flow(children) Bases: PythonBaseNode class parso.python.tree.IfStmt(children) Bases: Flow type: str = 'if_stmt' . get_test_nodes() test x : if x: pass elif x: pass get_corresponding_test_node(node) ( ). (suite) None . is_node_after_else(node) else . class parso.python.tree.WhileStmt(children) Bases: Flow type: str = 'while_stmt' . class parso.python.tree.ForStmt(children) Bases: Flow type: str = 'for_stmt' . get_testlist() y for x in y: . get_defined_names(include_setitem=False) class parso.python.tree.TryStmt(children) Bases: Flow type: str = 'try_stmt' . get_except_clause_tests() test except_clause . except [None] . class parso.python.tree.WithStmt(children) Bases: Flow type: str = 'with_stmt' . get_defined_names(include_setitem=False) Name with . as . get_test_node_from_name(name) class parso.python.tree.Import(children) Bases: PythonBaseNode get_paths: Any get_path_for_name(name) . Name (Return list of Name) is_nested() is_star_import() get_defined_names() class parso.python.tree.ImportFrom(children) Bases: Import type: str = 'import_from' . get_defined_names(include_setitem=False) Name import . import - as - . get_from_names() property level level __import__. get_paths() import. : [, ]. Name (Return list of list of Name) class parso.python.tree.ImportName(children) Bases: Import import_name. from . type: str = 'import_name' . get_defined_names(include_setitem=False) Name import . import - as - . property level level __import__. get_paths() is_nested() from : import foo.bar class parso.python.tree.KeywordStatement(children) Bases: PythonBaseNode : assert del global nonlocal raise return yield. pass continue break . property type _stmt . . property keyword get_defined_names(include_setitem=False) class parso.python.tree.AssertStmt(children) Bases: KeywordStatement property assertion class parso.python.tree.GlobalStmt(children) Bases: KeywordStatement get_global_names() class parso.python.tree.ReturnStmt(children) Bases: KeywordStatement class parso.python.tree.YieldExpr(children) Bases: PythonBaseNode type: str = 'yield_expr' . class parso.python.tree.ExprStmt(children) Bases: PythonBaseNode, DocstringMixin type: str = 'expr_stmt' . get_defined_names(include_setitem=False) Name = . get_rhs() (right-hand-side) . yield_operators() += = None . class parso.python.tree.NamedExpr(children) Bases: PythonBaseNode type: str = 'namedexpr_test' . get_defined_names(include_setitem=False) class parso.python.tree.Param(children, parent=None) Bases: PythonBaseNode . param . type: str = 'param' . property star_count foo 0 *foo 1 **foo 2 . property default = . None . property annotation : . None . property name Name . get_defined_names(include_setitem=False) property position_index . get_parent_function() . get_code(include_prefix=True, include_comma=True) get_code include_comma . (Parameters) bool (include_comma) -- . class parso.python.tree.SyncCompFor(children) Bases: PythonBaseNode type: str = 'sync_comp_for' . get_defined_names(include_setitem=False) Name (comprehension) . parso.python.tree.CompFor (alias) SyncCompFor class parso.python.tree.UsedNamesMapping(dct) Bases: Mapping (immutable dict) . (Utility) parso.tree.search_ancestor(node: NodeOrLeaf <#parso.tree.NodeOrLeaf>, *node_types: str ) -> BaseNode <#parso.tree.BaseNode> | None node_types . None . NodeOrLeaf.search_ancestor() . (Parameters) o node -- . o node_types -- . (Development) parso issue pull request . ! CONTRIBUTING.md . (Deprecations Process) : 1. (major/minor release) . 2. . (Testing) pytest : pip install pytest : pytest ( .) : python3.9 -m pytest GitHub Actions . (RESOURCES) o o GitHub Actions o (PyPI) (AUTHOR) parso (COPYRIGHT) parso 0.8 August 30, 2026 PARSO(1)