MimIR ships a Python package called mim. It wraps selected parts of the C++ API via nanobind and adds a small Python layer on top for convenience. The package is intentionally close to the C++ API. Names such as lit_i8, type_i32, arr, mut_con, and optimize are exposed with the same spelling you see in the C++ code. You have to enable MIM_BUILD_PYTHON (default) during configuration for Python support.
Activate that environment before importing mim:
Run the Python test suite with:
The public entry point is:
Internally, the package consists of a few layers:
The package also ships .pyi stubs, so editors and type checkers can see the exported binding surface.
The usual entry point is Driver, just like in C++:
Def objects are lightweight handles into the current World. The bindings currently expose a few frequently used helpers:
So the Python surface follows the same “named IR handle” model as the C++ API rather than copying nodes into Python-owned objects.
Runtime plugins are still discovered the same way as in C++. Driver() usually picks up the in-tree plugin build directory automatically, including from the editable Python package. Use add_search_path(...) only when you want to load plugins from an extra directory:
The package also stages generated Python enums for in-tree plugins. Those are re-exported as mim.plug.<name> modules:
For plugin calls, the convenience helper World.call(...) is the nicest entry point: It is designed around these generated plugin enums and folds each Python argument or argument list into implicit_app calls:
If you need finer control, call world.annex(...), world.implicit_app(...), or world.app(...) directly.
The top-level Python package adds a few small utilities for MimIR exceptions:
Available helpers:
These are ordinary Python wrappers around the MIM_Error exception type exported by the binding module.
The Python bindings are still intentionally selective. They already support useful workflows for:
But the Python API is not yet a one-to-one mirror of the full C++ surface. If you need a feature that exists in C++ but not in Python yet, the binding files under py/bindings/ are the place to extend.
The file mim.plug.regex provides a higher-level wrapper around the regex plugin in form of an embedded domain-specific language. It builds MimIR through overloaded operators, runs optimization, emits LLVM IR, invokes clang, and loads the resulting shared object via ctypes.
RegBuilder loads the required plugins by default, and pattern.jit() returns Python callables that wrap the exported compiled functions.