Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

interop

Maturin

  • https://github.com/PyO3/maturin
  • Builds and publishes Python native (machine code) modules that are written in Rust
  • Makes such modules available from Python registry as if they were normal Python packages

PyO3

Use Rust from Python

  • maturin init allows creating Cargo project setup for use with PyO3

  • maturin develop installs the package into a Python env such that it would be usable from Python

    >>> import written_in_rust
    >>> written_in_rust()
    

Use Python from Rust

  • Create Cargo project normally

  • Add pyo3 dep

    #![allow(unused)]
    fn main() {
    use pyo3::prelude::*
    }