Issue #1579: Decision: should Nikaia import and call Python modules (the direction ADR-284 does not cover)?

Open and answer this issue on GitHub.

decision · opened 2026-11-12 · updated 2026-11-12 · 0 comments

Where this comes from

An outside consultancy made suggestions to the owner on 2026-11-12. This is one of them: Python interoperability as Mojo has it, so that the Python ecosystem (numpy, pandas, ML libraries) is usable from Nikaia from day one. Half of this is decided. This issue files only the other half.

The question, from zero

Interoperability with Python has two directions:

Calling Python means embedding the CPython interpreter in the Nikaia process, or talking to a separate Python process. It brings dynamic types into a statically typed program, reference counting and Python’s global interpreter lock across the boundary, and a run-time dependency on an installed Python.

The question: should Nikaia offer calling into Python? If so, in what form: an embedded interpreter, a separate process, or only through the C ABI that already exists? And under which permission?

What exists that it builds on

How others do it

These facts are from memory, not checked.

Language How it calls Python
Mojo embeds CPython. Python.import_module("numpy") returns a PythonObject, a dynamically typed handle, and calls go through the interpreter at Python speed
Julia PythonCall.jl / PyCall.jl embed CPython, and values are converted or wrapped
Rust PyO3 can embed an interpreter as well as build extension modules. Calls return PyResult and need the GIL token
Swift PythonKit (formerly in Swift for TensorFlow), dynamic member lookup over an embedded CPython
AILANG, Boruna, Vera, Dafny no Python calls that I know of. Dafny compiles to Python instead

Options

  1. Do nothing. Python code is reached only by running it as a process (std.process, permission process), or by wrapping it in C.
    • For: no dynamic types in the language, no CPython dependency, and nothing for the permission proof to treat as opaque.
    • Against: the ML and data ecosystem is out of reach, and that is the ecosystem an AI-written program most often needs.
  2. A package that embeds CPython (Mojo’s model) with a PyObject handle type. Values are converted at the boundary (int, float, str, list and dict as std types) and errors come back as Result. It is a package in packages/, not part of the language, and it needs the native permission.
    • For: the whole Python ecosystem. No grammar change. It is opt-in and visible in the permission grants.
    • Against: dynamic calls the prover cannot see into, a CPython ABI to follow across versions, and the GIL. In the spirit of “no new Rust”, it needs C-ABI calls from Nikaia (ADR-290/393 cover Rust crates, not arbitrary C libraries). That may be a gap of its own.
  3. Typed bindings generated from Python stubs (.pyi files or typing annotations). A tool reads a module’s stubs and writes a typed Nikaia facade over option 2’s handle.
    • For: static types at the call site, and AI-friendly.
    • Against: stubs are often missing or wrong, and it is more work.
  4. A separate Python process with a typed message protocol.
    • For: no CPython in the process and a clean failure boundary. Permission process.
    • Against: slow for numeric work, and every value is copied.

Recommendation

Option 1 for now. Write down in ADR-284 that the reverse direction is not provided and why, and come back to option 2, as a package and never as language syntax, once calling C libraries from Nikaia is decided. The consultancy’s “from day one” argument is about the ecosystem’s reach. Weigh it against keeping the permission and proof story whole: an embedded interpreter is one large native hole.

What it touches

Back to Open Issues