2. Python, PyO3, and Maturin¶
2.1 Latest Stable Versions¶
- Python:
3.15.0(released October 9, 2026) pyo3:0.30.1maturin:1.15.0
2.2 Version Range Changelog (pyo3 0.24.0 - 0.30.1)¶
A. PyO3 0.25.0 - 0.26.0: Deprecation of extension-module Feature¶
- What changed: The Cargo feature
pyo3/extension-modulewas deprecated inpyo3 0.26.0. - Upstream technical rationale: Cargo features are additive across a workspace. When
extension-moduleis enabled inCargo.tomlto build.pyd/.somodules, runningcargo testin the same workspace fails at link time becauselibpythonsymbols are omitted whenextension-moduleis active. - New idiom: Extension module linking is controlled by the build system (
maturin >= 1.8) or viaPYO3_BUILD_EXTENSION_MODULE=1during manual compilation, rather thanfeatures = ["extension-module"]inCargo.toml.
B. PyO3 0.26.0 - 0.28.0: Removal of Python::allow_threads \(\rightarrow\) Python::detach¶
- What changed:
py.allow_threads(|| ...)was deprecated inpyo3 0.26.0and completely removed inpyo3 0.28.0. - Upstream technical rationale: With free-threaded Python (PEP 703 / PEP 803 without the GIL on Python 3.13–3.15),
allow_threadsis a misnomer because Python threads already run concurrently without a GIL; the operation actually detaches the Rust thread from the Python runtime. - New idiom: Use
py.detach(|| ...).
C. PyO3 0.24.0 - 0.30.1: Declarative #[pymodule] mod Declarations¶
- What changed: Legacy procedural
fn m(m: &Bound<'_, PyModule>) -> PyResult<()>blocks withm.add_function(wrap_pyfunction!(..., m)?)?were replaced by declarativemod-based module definitions. - New idiom:
D. PyO3 0.29.0 - 0.30.1 & Python 3.15: Stable ABI abi3t (PEP 803)¶
- What changed: Added the
abi3tfeature alongsideabi3-py310. - Upstream technical rationale: PEP 803 extends the Stable ABI (
abi3) to cover free-threaded Python builds (python3.14t/python3.15t) in addition to classic GIL builds.
2.3 Adaptations in LuminaMoon Source Code¶
Cargo.toml&pyproject.toml:- Removed
"extension-module"frompyo3features. - Configured
pyo3 = { version = "0.30.1", features = ["abi3-py310", "abi3t"] }. - Updated
requires = ["maturin>=1.15,<2.0"]inpyproject.toml. optimizer/src/python_ffi.rs:- Replaced
py.allow_threads(...)instep_pyo3withpy.detach(...): optimizer/src/lib.rs:- Migrated imperative module initialization to a declarative
#[pymodule] mod _luminamoon_optimizer_rsblock with#[pymodule_export]and#[pymodule_init].
2.4 Forward-Compatibility Architecture (Python 3.10 - 3.15+)¶
To guarantee zero-failure execution across future Python versions or environments lacking a Rust/C++ toolchain:
- Dual-Tier Forward Compatibility:
- Tier 1 (Stable ABI
abi3&abi3t): The CPython extension is compiled with PyO3features = ["abi3-py310", "abi3t"]. A single binary wheel built against the CPython 3.10 Stable ABI is automatically forward-compatible across Python 3.11, 3.12, 3.13, 3.14, and 3.15 in both standard GIL and free-threaded (Py_GIL_DISABLED) modes. - Tier 2 (Universal Pure-PyTorch / NumPy Fallback Engine): If the compiled
_luminamoon_optimizer_rsbinary is absent, corrupted, or running on an alternative interpreter,python/luminamoon/optimizer/luminav.pytransparently falls back to its pure-PyTorch/NumPy execution engine (_step_gpu_group) with identical mathematical convergence and stochastic rounding.