Calling & Building / Exporting Python Modules

Exporting Python Modules

One of Aero's killer features: turn Aero code into a native extension importable by Python with a single command.

Usage

#[py_export]
fn aggregate(data: String, price_col: i64) -> i64 {
    // ... 热循环
    return total;
}

Build:

aero build kernel.aero --pyext --py-module kernel

This produces kernel.pyd (Windows) / kernel.so, then:

import kernel
print(kernel.aggregate(b"1,100\n2,200\n", 1))

Type Conversion Table

i64intformat l (actually L, long long)
f64floatformat d
boolboolformat p
strstrUTF-8, format s
Stringbytesformat y#
no returnNone—

Return values: i64 → int, f64 → float, bool → bool, str → str, String → bytes.

Python Discovery Order

--py-home → PYTHON_HOME → probe python.

v1 locks the full CPython ABI: upgrading Python requires recompiling. The MSVC .lib of official Windows Python is automatically converted to a MinGW-compatible import library (cached in a temp directory).

Real-World Case: aero-csv

This is exactly how aero-csv works — aggregating a 2M-row CSV with aggregate() takes about 51ms (39M rows/s), 11× faster than pure Python and 9× faster than numpy. The entire hot loop is written in Aero; Python is left with just a thin glue layer.

Aero 文档 · 基于 Aero 1.2.0 文档整理 · MIT
SereinTeam