Atdpy: derive safe JSON interfaces for Python

On behalf of the ATD team, I’d like to announce atdpy, which is part of the release 2.3.x of the ATD tools. For now, the best installation method with via opam:

$ opam install atdpy

Atdpy is a new backend for ATD. It takes a collection of type definitions and derives Python classes with mypy type annotations that validate the JSON data.

A short introduction is included in the documentation.

Use cases:

  • Safe communication with another program that also uses an ATD interface. Other supported languages are OCaml (including Bucklescript), Java, and Scala.
  • Need for [mostly] type-safe Python methods via mypy.
  • Need for a good Python API to communicate with an OCaml executable or service.
  • Need for sum types (variants, algebraic data types, tagged unions). ATD sum types are ordinary types that include pure enums.

Atdpy was developed as part of our work on Semgrep at r2c. Many thanks to @mseri for his massive help during the opam release of the 7 ATD packages, and to the Ahrefs folks and @Khady in particular for supporting the project.


Are there small examples of use cases 1 and 3 available somewhere?

This is a simple working example showing JSON communication from OCaml to Python: