On this page
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
- > Essential CLI Workflow
- > Mixed Python + Rust Package Layout
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
- tuts/third_party/rust/pyo3 Linked here; links to this page; shared tags: #prog, #rust, #tier
- tuts/interop/rust_and_python_pyo3_maturin Linked here; links to this page; shared tags: #prog, #rust
- tuts/third_party/python3 Linked here; links to this page; shared tags: #prog
- tuts/rust/cargo_and_tooling links to this page; shared tags: #prog, #rust
- tuts/rust/cargo_and_tooling/cargo_workspaces_and_profiles links to this page; shared tags: #prog, #rust
- tuts/third_party/python3/wispsy links to this page; shared tags: #prog, #tier
- tuts/python3/tutorials/intermediate_python_and_software_engineering/modules_packages_and_tooling Linked here; shared tags: #packaging
- tuts/rust/builtins/Clone shared tags: #prog, #rust, #tier
- tuts/rust/builtins/Copy shared tags: #prog, #rust, #tier
- tuts/rust/builtins/Drop shared tags: #prog, #rust, #tier