maturin: three commands and the packaging rules behind them
Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
At a glance
- What is it?
- maturin turns Rust crates with pyo3, cffi, or uniffi bindings into Python wheels with almost no configuration, and it can upload them to pypi. The parts worth understanding are the naming rules, the gap between build and develop, and what Linux publishing costs.
- Who is it for?
- maturin earns its place when you have a Rust extension to ship and no appetite for hand-written packaging glue, since it takes a crate from cargo manifest to installable wheel without extra configuration files and keeps working beside an existing setuptools-rust setup.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 6 days ago.
- What is it written in?
- Mainly Rust, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 22, 2026, and from our analysis. They are not legal advice.
Star history
- PyO3/maturin5,902 ★ · +88
| Repository | 2026-09-23 | 2026-11-22 |
|---|---|---|
| PyO3/maturin | 5.8k | 5.9k |
88 Stars in the last 60 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
maturin build fills target/wheels and stops before publishing
Three commands carry the daily work. `maturin new` creates a new cargo project with maturin already configured. `maturin build` builds the wheels and stores them in a folder, `target/wheels` by default, and does not upload them. `maturin develop` builds the crate and installs it as a Python module directly in the current virtualenv.
That third command is deliberately narrower than a build plus install. `maturin build` itself does not upload, and the README recommends publishing with uv, using `uv publish`, although maturin can also upload wheels to pypi.
Two details get missed. Both build commands accept `-r` or `--release`, which is what you want for anything users will run, since an unoptimized build of a compiled extension is slow. And maturin needs no extra configuration files and does not clash with an existing setuptools-rust configuration, so a project that already has one does not have to be rewritten to try it. It also integrates with testing tools such as tox, and the `test-crates` folder in the repository holds working examples for the different bindings.
pipx and uv are the two documented install paths
The binary comes from one of three places: a download from the latest release page, pipx, or uv.
# pipx
pipx install maturin
# uv
uv tool install maturin`pip install maturin` also works, which matters because maturin is itself a Python package and lands in whatever environment you point pip at. Installing it as an isolated tool keeps it out of your project environments. Either way you still need a Rust toolchain, since maturin drives cargo rather than replacing it.
Two version floors appear in the repository, and they mean different things. The pyproject.toml sets requires-python to >=3.7 for installing maturin itself, and the Cargo.toml asks for edition 2024 with rust-version 1.89. The 3.8+ figure in the README is about what the wheels maturin produces can be installed on, across Windows, Linux, macOS, and FreeBSD, alongside what the project calls basic PyPy and GraalPy support. Confusing the floor for the builder with the floor for the built package is an easy mistake.
The wheel takes its name from Cargo.toml and the module name from [lib]
Naming is where mixed projects go wrong, and maturin resolves it with two separate fields. The package name is the name of the cargo project, in other words the `name` field in the `[package]` section of Cargo.toml. The module name, the one you write in your import statement, is the `name` value in the `[lib]` section, which defaults to the package name. For binaries it is simply the name of the binary cargo generates.
Those two values being independent is the point. A project can publish `my-project` on the index and expose `my_project` inside Python, letting the hyphen and the underscore do different jobs in different worlds.
A third name appears when you set `module-name` yourself, for instance `module-name = "my_project._lib_name"`. The last part, `_lib_name`, is what the Rust side has to declare, and the attribute on the module function carries the same string:
#[pymodule]
#[pyo3(name="_lib_name")]
fn my_lib_name(m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_class::<MyPythonRustClass>()?;
Ok(())
}Get that mismatch wrong and the import fails at runtime.
pyproject.toml wins over Cargo.toml and console scripts take no arguments
Metadata can live in either file. maturin supports PEP 621, so Python package metadata goes in pyproject.toml, and when both files carry the same field, pyproject.toml takes precedence over Cargo.toml. Dependencies belong in a `dependencies` list inside a `[project]` section, and that list is equivalent to install_requires in setuptools:
[project]
name = "my-project"
dependencies = ["flask~=1.1.0", "toml>=0.10.2,<0.11.0"]Console scripts are declared in `[project.scripts]`. Keys are the command names you type, values are a path to a function written as `some.module.path:class.function`, where the class part is optional, and the function is called with no arguments:
[project.scripts]
get_42 = "my_project:DummyClass.get_42"Trove classifiers go under `project.classifiers` in the same pyproject.toml.
A bootstrap build backend exists because maturin cannot depend on itself
maturin builds itself, which creates a bootstrap problem on platforms that are neither manylinux nor musllinux. FreeBSD is the case named in setup.py. There pip falls back to the source distribution, an sdist cannot depend on maturin, and setuptools is always available, so a `bootstrap` build backend sits in front with setuptools-rust behind it:
[build-system]
requires = [
"setuptools>=77.0.0",
"tomli>=1.1.0 ; python_version<'3.11'",
"setuptools-rust>=1.11.0",
]
backend-path = ["maturin"]
build-backend = "bootstrap"This is called a bootstrap workaround rather than a general packaging route, and setup.py is correspondingly limited: only building a wheel with `python setup.py bdist_wheel` and installing with `pip install <source dir>` are supported. To produce a source distribution for maturin itself you use `maturin sdist` instead. The same file reads the version straight out of Cargo.toml, forces the wheel to be platform specific by setting root_is_pure to False, and passes `--no-default-features` to cargo by default, with the `MATURIN_SETUP_ARGS` environment variable replacing that argument list when you need something else.
Linux wheels need manylinux2014 or zig, GitHub publishing needs maturin-action
Publishing is where platform requirements stop being abstract. Wheels come in two shapes: one that works across Python versions, interpreters, operating systems, and hardware architectures, which is the pure Python case, and one limited to a specific platform and architecture, such as when using ctypes or cffi, or to a specific interpreter and version on a specific platform, which is the pyo3 case. A crate with compiled code always lands in the second category.
For Linux that rules out a plain build and upload. You need either the manylinux Docker container or zig, and the repository Dockerfile shows how the container path works: an ARG defaulting to MANYLINUX=manylinux2014, x86_64 and aarch64 base images from quay.io/pypa, and musl cross builders compiling against a cached target directory. The finished binary is moved to /usr/bin/maturin in the final stage, and the PATH line adds /opt/python/cp39-cp39/bin and /opt/python/cp310-cp310/bin so several interpreters are reachable from one image. Publishing from your own repository instead means the PyO3/maturin-action GitHub action, and checking a candidate before release takes one flag:
pip install --index-url https://test.pypi.org/simple/The reason any of this matters is speed. pip prefers a matching wheel, and falls back to downloading an sdist and building a wheel for the current platform, which needs the right compilers present.
The ImportError trap behind tool.maturin.python-source
A mixed Rust and Python project puts a Python package folder next to Cargo.toml, named after `lib.name`, with the Python sources inside it. The layout the README recommends is the one that avoids a common ImportError, tracked as issue 490, and moving the Python code elsewhere is what `python-source` is for:
[tool.maturin]
python-source = "python"
module-name = "my_project._lib_name"Two consequences follow from `maturin develop` specifically. It copies the native library into your Python folder, and for cffi the glue code too, so those copied files belong in your gitignore. The example layout shows the result as `_lib_name.cpython-36m-x86_64-linux-gnu.so` sitting next to `__init__.py` and `bar.py`. The import style then differs by binding: with cffi you write `from .my_project import lib` and call `lib.my_native_function`, while with pyo3 you go straight to `from .my_project import my_native_function`.
The repository keeps its own experiments in view at the top level, with test-crates, sysconfig, test-data, and tests directories alongside guide, noxfile.py, clippy.toml, deny.toml, and a maturin.schema.json.
Editorial conclusion
maturin earns its place when you have a Rust extension to ship and no appetite for hand-written packaging glue, since it takes a crate from cargo manifest to installable wheel without extra configuration files and keeps working beside an existing setuptools-rust setup. It is the wrong tool for a pure Python library, and the README recommends publishing with uv publish, with the manylinux container or zig needed for Linux and the maturin-action workflow for publishing from your repository. Before trusting it, check the three details that catch people: run the candidate through the test index with pip install --index-url, accept that console script targets are called with no arguments, and decide whether the develop versus build feature gap matters for how you work.
Frequently asked questions
what is maturin
It builds and publishes crates with pyo3, cffi, and uniffi bindings, plus plain Rust binaries, as Python packages with minimal configuration. It was formerly called pyo3-pack, and it can upload the results to pypi.
how to install maturin
Download the binary from the latest release page, or install it as an isolated tool with pipx install maturin or uv tool install maturin. A plain pip install maturin also works if you would rather not use pipx.
how to use maturin
Three commands cover most of it: maturin new scaffolds a project, maturin build writes wheels into target/wheels without uploading them, and maturin develop installs the crate into the current virtualenv. Add -r or --release to compile an optimized build.
what is maturin rust
For a Rust crate, maturin handles the wheel build. The package name comes from the name field in the [package] section of Cargo.toml, the importable module name from the [lib] name, and building maturin itself asks for edition 2024 with rust-version 1.89.
what is maturin python
On the Python side, metadata is read from pyproject.toml under PEP 621, and pyproject.toml takes precedence over Cargo.toml when both set the same field. The wheels it builds install on Python 3.8+ across Windows, Linux, macOS, and FreeBSD.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/pyo3-maturin)Star history chart for your README
[](https://hysenlabs.com/projects/pyo3-maturin)Was this useful?