liveBook · Manning

Maturin

As explained in Refactoring to Rust

Maturin is a build and packaging tool for developing Python modules implemented in Rust.

Maturin is a command-line tool for developing Python modules implemented in Rust. It sets up development environments for Rust-based Python extensions and builds distribution-ready packages. section 6.4 section 6.7

A typical development workflow is:

  • Create and activate a Python virtual environment, because maturin develop must run inside one. section 6.4
  • Run maturin develop to compile the Rust extension and install it for immediate Python use. section 6.7

Importing a Rust extension

Before building, importing rust_json fails with ModuleNotFoundError. After activating the environment and running maturin develop, Python imports rust_json successfully and can call rust_json.sum on a JSON string.

How Refactoring to Rust covers it

How deep it goes
Explains installation, virtual-environment setup, compilation, installation, and import validation, but not maturin internals.
Examples
Uses the rust_json extension, maturin develop, Python imports, and a JSON-line processing program.
What it assumes
Assumes basic Python package installation and virtual-environment commands while introducing Rust extension integration through PyO3.
What you can do after
Operate maturin develop to compile, install, import, and call a Rust-based Python module inside an isolated environment.
How it connects
Connects Rust, Python, PyO3, Python virtual environments, and Cargo-based extension configuration.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.