A Swift library set for parsing, inspecting, generating and transforming Swift source code as a source-accurate syntax tree.
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
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
A unist utility for walking and visiting nodes in syntax trees such as Markdown ASTs, with a test filter and enter/exit visitors.
An incremental parser generator and parsing library that builds concrete syntax trees and updates them as source files are edited.
A complete C99/C11 parser written in pure Python, producing an AST from C source code with no external dependencies.
A JavaScript tool for transforming CSS with plugins, used to lint, prefix, nest, minify and extend stylesheets.
A PHP parser written in PHP that turns PHP source code into an abstract syntax tree for static analysis and code manipulation.