/pyo3-example

Example using Python and Rust with PyO3

Primary LanguageMakefileApache License 2.0Apache-2.0

pyo3

Summary

Example of a PyO3 project integrating Python and Rust.

Setup the project

Setup pre-commit

https://pre-commit.com/

Create a new project with maturin

  1. Install maturin
pipx install maturin
  1. Get help on maturin
maturin --help
  1. Get help on maturin new command
maturin new --help
  1. Create a new mixed Python & Rust project
maturin new --bindings pyo3 --mixed my_project

Setup rust tools

Make sure that the following rust tools are in the path

rust-analyzer --version
rustfmt --version

Build the Python module

maturin develop

Test project

  1. Run test Python files
make pytest
  1. Run test Rust files
cargo test

Links

Python and Rust project with PyO3 bindings

Calling Rust from Python using PyO3

From Python to Rust

Nine rules for Python extensions in Rust

Python-numpy with Rust-ndarray