Repolode
davidhalter

davidhalter/parso

A Python parser that builds syntax trees with error recovery and round-trip source preservation across Python versions.

Stars
678
Forks
131
Open issues
11
Last commit
5 days ago

What is it?

Parso parses Python source code into a syntax tree and analyses it through a small API. Unlike the standard library's ast module, it keeps whitespace and comments, so calling get_code() on a node reproduces the original text exactly. It also recovers from syntax errors instead of stopping at the first one, and can report several issues in a single file.

Parso supports parsing code for different Python versions by loading a grammar for a chosen version. It was originally extracted from the Jedi project and is used as the parsing layer for editor tooling that needs to work on incomplete or broken code while the user is typing.

The project is installed with pip and provides functions such as parso.parse() and parso.load_grammar() for working with trees and listing errors.

Key features

  • 01Error recovery that keeps parsing after syntax errors.
  • 02Round-trip parsing that preserves whitespace and comments.
  • 03Lists multiple syntax errors in a single file.
  • 04Supports selecting a specific Python version grammar.
  • 05Small API for navigating and analysing the syntax tree.

Use cases

  • Building editor or IDE tooling that must handle incomplete code.
  • Writing source code refactoring or transformation tools that need exact text round-trips.
  • Reporting multiple syntax errors in a Python file at once.
  • Analysing Python code across different Python version grammars.

Quick start

  1. 1

    Install parso from PyPI with pip

    pip install parso

Things to know

  • Has known issues with async/await keywords on Python 3.6 and with from __future__ print_function handling.
  • Lists a work-in-progress PEP8 validator that is not yet in good shape.
  • License is not clearly specified in the metadata.

Topics

FAQ

What is parso?
A Python parser that builds syntax trees with error recovery and round-trip source preservation across Python versions. Parso parses Python source code into a syntax tree and analyses it through a small API. Unlike the standard library's ast module, it keeps whitespace and comments, so calling get_code() on a node reproduces the original text exactly. It also recovers from syntax errors instead of stopping at the first one, and can report several issues in a single file.
Is parso free to use? What license does it have?
parso is open source under the Other license. Check the license terms before using it in commercial products.
Is parso still maintained?
Actively maintained. The last commit to parso was on Nov 2, 2026.
What can I use parso for?
Building editor or IDE tooling that must handle incomplete code. Writing source code refactoring or transformation tools that need exact text round-trips. Reporting multiple syntax errors in a Python file at once. Analysing Python code across different Python version grammars.
How do I install parso?
Install parso from PyPI with pip: pip install parso
Where can I get parso?
The source code and installation instructions are on GitHub: https://github.com/davidhalter/parso

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects