A sample implementation of a Python module with a Rust backend
This Python module uses Rust code for performance-critical parts. The standard approach is using PyO3, which makes creating Python extensions in Rust straightforward.
- Checkout the repository
git clone https://github.com/hstm/python-rust-module.git
- Create a Python venv
python -m venv rust_module
and activate itsource rust_module/bin/activate
- Install maturin
pip install maturin
- Run
maturin develop
to build and install the Python wheel.
Then in your Python shell, run some tests with the new module:
from my_rust_module import fast_computation, process_with_validation
result1 = fast_computation(100)
result2 = process_with_validation([1.0, 4.0, 9.0, 16.0])