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: a typed subset with Rust semantics. Owned collections, exceptions, typed classes and supported Polars operations compile. Unsupported constructs are refused with their line. Building needs cargo.

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 of owned values, moves and borrows (Python that needs two names for one changing list is refused), keeping Python's floor division and float printing.

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))

A compiled program behaves as the Rust it becomes, and each test case's output is written down beside it. Where Python and Rust agree (no overflow, no float that prints differently, ASCII), CPython 3.14 must print the same, byte for byte.

What compiles today

  • int (checked i64), float, bool and str; list, dict, tuple and sets; X | None after a None check
  • def with annotations or types from its calls; if, while, for over ranges, lists, dicts, strs, enumerate, zip; comprehensions; recursion
  • try / except / else / finally, raise, the errors the program itself raises, caught by CPython's names
  • typed classes, single inheritance among the program's classes, super() and isinstance; exception subclasses
  • generator functions consumed directly by a for loop or a builtin; nested functions and closures remain limited
  • print and f-strings, len, min, max, sum, sorted, any, all, str methods, split and join

Every platform rustc reaches

Cross-compilation and runtime coverage are separate. The test suite records the following host, emulator and simulator paths; these are not physical-device acceptance:

TargetRun onNeeds
this machine (macOS, Linux)every casecargo
wasm32-wasip1 — a programwasmtime; refuses try (wasm32 does not unwind)nothing
wasm32-unknown-unknown — a librarynode, through the data-fr-js gluenothing
aarch64-linux-androidan Android emulator, over adbthe NDK
aarch64-apple-ios-simthe iOS simulatorXcode
x86_64-pc-windows-gnubuilt; not run yetcargo zigbuild

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
polarspolarsCSV, expressions, filter/select, with_columns, stable sort and group_by/agg
orjsonorjsonnot bundled; would require an export binding
tokenizerstokenizersnot bundled; would require an export binding
safetensorssafetensorsnot bundled; would require an export binding
pydantic-corepydantic-corenot bundled; would require an export binding

A supported Polars pipeline, checked against Python's CSV output:

import polars as pl

df = pl.read_csv("people.csv")
out = df.filter((pl.col("age") > 30) & ~(pl.col("city") == "Reus")).select(["name", "score"])
out.write_csv("out.csv")
print(out.height)

What it refuses, with the line

  • multiple inheritance and subclassing builtin containers
  • a generator stored as a value and advanced with next()
  • printing an object with no __repr__ (CPython prints its address)
  • floats where they have no order: sorting them, a float dict key or set item
  • an empty [] or {} or None with no annotation; a list of mixed types
  • unsupported Polars calls/options, unstable sort/group ordering, or a Polars operation inside try

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.

© Optersoft, S.L.