On this page
  1. Maturin
  2. Contents
  3. Overview & pyproject.toml Configuration
  4. Essential CLI Workflow
  5. Mixed Python + Rust Package Layout

Maturin

Prev: third_party/python3 | Up: third_party/python3 | Next: Rust & Python (PyO3 + Maturin)
Rel: PyO3, Rust & Python (PyO3 + Maturin), Python Modules, Packages & Tooling
Ref: Maturin User Guide
Tags: #public #prog #python3 #rust #third-party #packaging #tier/core


Contents


Overview & pyproject.toml Configuration

Maturin is a PEP 517 build backend and CLI that compiles Rust crates (most commonly PyO3) directly into installable Python wheels (.whl) without hand-writing setup.py or CMake scripts.

[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[project]
name = "fast-ext"
version = "0.1.0"
requires-python = ">=3.11"

[tool.maturin]
features = ["pyo3/extension-module"]
python-source = "python"
module-name = "fast_ext._native"

Essential CLI Workflow

# Scaffold a new PyO3 + Maturin project
maturin new --bindings pyo3 fast_ext

# Compile & install directly into the active virtualenv (use --release for benchmarks!)
maturin develop --release

# Build distributable wheels into target/wheels/
maturin build --release

Mixed Python + Rust Package Layout

Keep public Python APIs, docstrings, and .pyi type stubs in python/fast_ext/, while re-exporting compiled Rust symbols from the internal _native extension:

fast_ext/
├── Cargo.toml
├── pyproject.toml
├── src/
│   └── lib.rs                # Compiled to fast_ext/_native.so
└── python/
    └── fast_ext/
        ├── __init__.py       # from ._native import sum_squares, Counter
        └── _native.pyi       # Type stubs for IDEs & type checkers

Linked from

Related notes