maturin
Build and publish Python wheels that bundle Rust extensions with maturin.
Search across all documentation pages
Build and publish Python wheels that bundle Rust extensions with maturin.
# pyproject.toml
[build-system]
requires = ["maturin>=1.8"]
build-backend = "maturin"
[project]
name = "myrust"
requires-python = ">=3.10"maturin develop --releaseWhen to reach for this: Shipping PyO3 extensions to PyPI or internal package indexes with standard Python tooling.
# Cargo.toml
[package]
name = "myrust"
version = "0.1.0"
edition = "2024"
[lib]
name = "myrust"
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.23", features = ["extension-module"] }# pyproject.toml
[tool.maturin]
module-name = "myrust"
python-source = "python"
features = ["pyo3/extension-module"]python/
myrust/
__init__.py # re-exports
maturin build --release --out dist
pip install dist/myrust-0.1.0-*.whlWhat this demonstrates:
cdylib crate type produces the native moduleextension-module feature tells PyO3 it is loaded by Pythonmaturin develop installs into active venv for fast iterationmaturin build emits platform-specific wheels in dist/| Command | Use |
|---|---|
maturin develop | Local editable install |
maturin build | Produce wheels for CI |
maturin publish | Upload to PyPI |
maturin generate-ci | GitHub Actions template |
[dependencies]
pyo3 = { version = "0.23", features = ["extension-module", "abi3-py39"] }One wheel per platform covers Python 3.9+.
my-package/
Cargo.toml
pyproject.toml
python/mypkg/__init__.py
src/lib.rs
maturin develop.maturin build --compatibility manylinux_2_28 or CI docker images.maturin build --target universal2-apple-darwin.license in pyproject.toml and include LICENSE in manifest.| Alternative | Use When | Don't Use When |
|---|---|---|
setuptools-rust | Legacy setuptools workflows | New PyO3 projects |
cffi + prebuilt dll | Users cannot compile Rust | You control all platforms |
uv build with maturin backend | Modern Python packaging | N/A for Rust extensions |
maturin understands Rust layout and PyO3 features. Plain pip may miss extension build steps.
Use maturin as PEP 517 backend. Poetry manages deps; maturin builds the extension.
uv pip install works on maturin-built wheels. uv sync in hybrid repos needs documented develop workflow.
maturin publish --repository-url https://internal/simple/.
Normal Cargo dependencies. maturin runs cargo build under the hood.
Put .pyi files in python/ package for type checkers.
Use cross toolchains and maturin target flags in CI matrix.
maturin develop without --release for faster builds; slower runtime.
maturin supports workspaces with manifest-path pointing to the extension crate.
pip audit and cargo deny for dual-language supply chain checks.
Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Reviewed by Chris St. John·Last updated Jul 16, 2026