# \[ANN\] pyre-ast: full-fidelity Python parser in OCaml

**URL:** <https://discuss.ocaml.org/t/ann-pyre-ast-full-fidelity-python-parser-in-ocaml/8177>\
**Category:** Community\
**Tags:** announce\
**Created:** [July 21, 2021, 8:49pm UTC](https://discuss.ocaml.org/t/ann-pyre-ast-full-fidelity-python-parser-in-ocaml/8177 "2021-07-21T20:49:57Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![grievejia](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/grievejia/32/3096_2.png) [@grievejia](https://discuss.ocaml.org/u/grievejia)\
**Post date:** [July 21, 2021, 8:49pm UTC](https://discuss.ocaml.org/t/ann-pyre-ast-full-fidelity-python-parser-in-ocaml/8177/1 "2021-07-21T20:49:57Z")

</div>

I am happy to announce the initial opam release of [`pyre-ast`](https://github.com/grievejia/pyre-ast), a Python parsing library.

The library features its full-fidelity to the official Python spec. Apart from a few technical edge cases, as long as a given file can be parsed/rejected by the CPython interpreter, `pyre-ast` will be able to parse/reject it as well. Furthermore, abstract syntax trees obtained from `pyre-ast` is guaranteed to 100% match the results obtained by Python’s own `ast.parse` API, down to every AST node and every line/column number.

Another notable feature of this library is that it represents the Python syntax using the _tagless-final style_. This style typically offers more flexibility and extensibility for the downstream consumers of the syntax, and allow them to build up their analysis without explicitly constructing a syntax tree. That said, for developers who are less familiar with the tagless-final approach, we also offer alternative interfaces that operates on traditional syntax tree represented as algebraic data types.

Documentation of the library can be found [here](https://grievejia.github.io/pyre-ast/doc/pyre-ast/).

* * *

The reason why we can can claim full-conformance with CPython is really simple: the library is, under the hood, merely an OCaml wrapper around the parsing logic in CPython source code. The project was initially motivated to replace the custom `menhir`-based parser currently used in the Pyre type checker (hence the name), but I figured that it would be useful to release this as a standalone `opam` package to the community so other static Python analyzers or other DSLs with Python-based syntax can leverage it as well.

The library has yet to be put into production for Pyre (I’m working on it though) so please do expect bugs/jankiness at times. Feedback and bug reports are very welcomed.

Happy parsing!

---

_[View the full topic](https://discuss.ocaml.org/t/ann-pyre-ast-full-fidelity-python-parser-in-ocaml/8177)._
