Skip to content

Python in, native out

oxid aot

oxid aot compiles typed Python into Rust, and Rust into a native binary or WebAssembly — for Linux, macOS, Windows, Android, iOS and the browser. No interpreter ships with the result. Libraries are accepted only when they are already Rust underneath, like Polars, so a library call becomes the Rust call it always was.

uvx oxid aot build fib.py --target wasm32-unknown-unknown

Status: early. The compiler handles annotated functions over int, float, bool and str, loops, recursion and print, and refuses everything else with its line. It writes Rust, so it needs cargo on the machine that builds.

How it works

1 · Parse

Ruff's Rust parser reads the file — the same one the VM's compiler uses.

2 · Type

Every value gets one concrete type, worked out from the entry function's annotations. A value that could be two things is a compile error that names the line.

3 · Emit Rust

A small Rust crate, with Python's semantics kept where Rust differs: floor division, shared lists, how a float prints.

4 · Build

cargo build --target — every platform rustc reaches, from one machine.

A program it will compile

def fib(n: int) -> int:
    return n if n < 2 else fib(n - 1) + fib(n - 2)


def main() -> None:
    print(fib(30))

The test of every compiled program is the same: its output must equal what CPython 3.14 prints for the same file, byte for byte.

Libraries that are already Rust

Re-implementing NumPy is a project without an end. oxid aot accepts a library only when its Python package is a binding over a Rust crate, and calls the crate.

Python packageRust crateScope
polarspolarsfirst: one read → filter → select → write pipeline
orjsonorjsondumps and loads
tokenizerstokenizersmodel pre- and post-processing
safetensorssafetensorsloading weights
pydantic-corepydantic-corevalidation

What it will not do

  • Run code it cannot type. It refuses it, with the line, instead of guessing.
  • Call a C extension. NumPy, SciPy and OpenCV are out of scope.
  • Ship an interpreter. If the program needs one, that is the VM's job.

Apache 2.0 · Optersoft, S.L.