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 kernelThis produces kernel.pyd (Windows) / kernel.so, then:
import kernel
print(kernel.aggregate(b"1,100\n2,200\n", 1))Type Conversion Table
i64 | int | format l (actually L, long long) |
f64 | float | format d |
bool | bool | format p |
str | str | UTF-8, format s |
String | bytes | format y# |
| no return | None | — |
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.