Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Avhz RustQuant Python Integration

From Leeroopedia


Knowledge Sources
Domains Software_Engineering, Interoperability
Last Updated 2026-02-07 21:00 GMT

Overview

PyO3-based Python bindings exposing RustQuant's quantitative finance functionality to the Python ecosystem.

Description

Python Integration in RustQuant is achieved through PyO3, a Rust crate that provides seamless interoperability between Rust and Python. The bindings are organized as a Python package named RustQuant with hierarchical submodules that mirror the Rust crate structure.

The top-level #[pymodule] function registers three submodules:

  • RustQuant.data -- Exposes the Curve, CurveType, and InterpolationMethod classes for working with financial curves (yield curves, discount curves, etc.). These types are annotated with #[pyclass] and #[pymethods] in the Rust source.
  • RustQuant.instruments -- A placeholder module for financial instrument classes (currently under development).
  • RustQuant.time -- Exposes the Calendar and Market classes for date handling, holiday calendars, and market conventions.

Each submodule is registered with Python's sys.modules dictionary, enabling standard Python import semantics such as from RustQuant.data import Curve. The bindings project uses maturin for building and packaging, as configured in a pyproject.toml.

Usage

Use the Python Integration principle when you need to access RustQuant's high-performance quantitative finance tools from Python code. This is particularly useful for data scientists and quantitative analysts who work primarily in Python but want the performance benefits of Rust for compute-intensive operations like curve fitting, option pricing, and calendar calculations.

Theoretical Basis

The integration follows the Foreign Function Interface (FFI) pattern, where Rust functions are compiled into a shared library (.so or .pyd) that Python can load as a native extension module. PyO3 handles the type conversion between Rust and Python types automatically, including:

  • Rust f64 maps to Python float
  • Rust String maps to Python str
  • Rust Vec<T> maps to Python list
  • Rust structs annotated with #[pyclass] become Python classes

The module registration pattern uses nested PyModule objects and the sys.modules dictionary to enable dotted import paths:

#[pymodule]
fn RustQuant(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
    register_data_module(py, m)?;
    register_instruments_module(py, m)?;
    register_time_module(py, m)?;
    Ok(())
}

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment