A Python Parser
################################################################### parso - A Python Parser ###################################################################
.. image:: https://github.com/davidhalter/parso/workflows/Build/badge.svg?branch=master :target: https://github.com/davidhalter/parso/actions :alt: GitHub Actions build status
.. image:: https://coveralls.io/repos/github/davidhalter/parso/badge.svg?branch=master :target: https://coveralls.io/github/davidhalter/parso?branch=master :alt: Coverage Status
.. image:: https://pepy.tech/badge/parso :target: https://pepy.tech/project/parso :alt: PyPI Downloads
.. image:: https://raw.githubusercontent.com/davidhalter/parso/master/docs/_static/logo_characters.png
Parso is a Python parser that supports error recovery and round-trip parsing for different Python versions (in multiple Python versions). Parso is also able to list multiple syntax errors in your python file.
Parso has been battle-tested by jedi_. It was pulled out of jedi to be useful for other projects as well.
Parso consists of a small API to parse Python and analyse the syntax tree.
A simple example:
.. code-block:: python
>>> import parso
>>> module = parso.parse('hello + 1', version="3.9")
>>> expr = module.children[0]
>>> expr
PythonNode(arith_expr, [<Name: hello@1,0>, <Operator: +>, <Number: 1>])
>>> print(expr.get_code())
hello + 1
>>> name = expr.children[0]
>>> name
<Name: hello@1,0>
>>> name.end_pos
(1, 5)
>>> expr.end_pos
(1, 9)
To list multiple issues:
.. code-block:: python
>>> 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"
Testing <https://parso.readthedocs.io/en/latest/docs/development.html#testing>
_PyPI <https://pypi.python.org/pypi/parso>
_Docs <https://parso.readthedocs.org/en/latest/>
_semantic versioning <https://semver.org/>
_pip install parso
async
/await
are already used as keywords in Python3.6.from __future__ import print_function
is not ignored.Salome Schneider <https://www.crepes-schnaegg.ch/cr%C3%AApes-schn%C3%A4gg/kunst-f%C3%BCrs-cr%C3%AApes-mobil/>
_
for the extremely awesome parso logo... _jedi: https://github.com/davidhalter/jedi
.. :changelog:
Unreleased ++++++++++
0.8.3 (2021-11-30) ++++++++++++++++++
0.8.2 (2021-03-30) ++++++++++++++++++
0.8.1 (2020-12-10) ++++++++++++++++++
0.8.0 (2020-08-05) ++++++++++++++++++
pathlib.Path
objects now in the APInamedexpr_test
nodes are now a proper class called NamedExpr
0.7.1 (2020-07-24) ++++++++++++++++++
Grammar.iter_errors
)This is going to be the last release that supports Python 2.7, 3.4 and 3.5.
0.7.0 (2020-04-13) ++++++++++++++++++
0.6.2 (2020-02-27) ++++++++++++++++++
0.6.1 (2020-02-03) ++++++++++++++++++
parso.normalizer.Issue.end_pos
to make it possible to know where an
issue ends0.6.0 (2020-01-26) ++++++++++++++++++
name.is_definition()
)0.5.2 (2019-12-15) ++++++++++++++++++
0.5.1 (2019-07-13) ++++++++++++++++++
0.5.0 (2019-06-20) ++++++++++++++++++
0.4.0 (2019-04-05) ++++++++++++++++++
0.3.4 (2019-02-13) +++++++++++++++++++
0.3.3 (2019-02-06) +++++++++++++++++++
0.3.2 (2019-01-24) +++++++++++++++++++
0.3.1 (2018-07-09) +++++++++++++++++++
0.3.0 (2018-06-30) +++++++++++++++++++
0.2.1 (2018-05-21) +++++++++++++++++++
0.2.0 (2018-04-15) +++++++++++++++++++
0.1.1 (2017-11-05) +++++++++++++++++++
0.1.0 (2017-09-04) +++++++++++++++++++