# Python interface

MC Grating's Python interface, implemented in the 2021-05-10 release for the Modal Crossed code: what it covers, where its documentation lives, and how it pairs with the JSON output the codes write since 2021.

Canonical: https://mcgrating.com/features/python-api.html


Since 2021 the Modal Crossed code can be driven from Python. It is documented on its own site, outside the in-application help.

## What exists

The 2021-05-10 release introduced it, in these words: The Python interface is implemented. Only Modal Crossed version is supported at the moment. More details here: [mc-grating-python.readthedocs.io](https://mc-grating-python.readthedocs.io/en/latest/). Credits to Dorian Herle. That external site is the reference documentation: installation, the objects that describe a crossed-grating structure, and how a calculation is launched and its results read back.

The interface exists for the [Modal Crossed](https://mcgrating.com/products.html#modal-crossed) code; the other five codes are operated through their Windows interface or the [command line](https://mcgrating.com/docs/common/command-line.html), and their results are read from the text tables or, since 2021, from the [JSON files](https://mcgrating.com/features/json-output.html) the codes write.

## Why it matters

Everything the interface computes is what Modal Crossed computes: the same FMM with the automatically generated normal-vector field, the same materials catalogue, the same license. What Python adds is the loop around it — a parameter study, an optimisation with a criterion the built-in [optimizer](https://mcgrating.com/features/optimization.html) does not offer, or a batch of structures generated from another program — and a place for the results other than a text window.

## Status

The interface is not described in the in-application help, which was last revised in 2018, and it is not part of the installer: follow the external documentation for how to obtain it. The changelog is the record of what changed on the MC Grating side; write to [mc@mcgrating.com](mailto:mc@mcgrating.com) if you want to use it with a licensed copy.
