Local Development

maturin develop command

For local development, the maturin develop command can be used to quickly build a package in debug mode by default and install it to virtualenv.

Usage: maturin develop [OPTIONS] [ARGS]...

          Rustc flags

  -b, --bindings <BINDINGS>
          Which kind of bindings to use. Possible values are pyo3, rust-cpython, cffi and bin

  -r, --release
          Pass --release to cargo

          Strip the library for minimum file size

  -E, --extras <EXTRAS>
          Install extra requires aka. optional dependencies

          Use as `--extras=extra1,extra2`

  -q, --quiet
          Do not print cargo log messages

  -j, --jobs <N>
          Number of parallel jobs, defaults to # of CPUs

      --profile <PROFILE-NAME>
          Build artifacts with the specified Cargo profile

  -F, --features <FEATURES>
          Space or comma separated list of features to activate

          Activate all available features

          Do not activate the `default` feature

      --target <TRIPLE>
          Build for the target triple

          [env: CARGO_BUILD_TARGET=]

      --target-dir <DIRECTORY>
          Directory for all generated artifacts

  -m, --manifest-path <PATH>
          Path to Cargo.toml

          Ignore `rust-version` specification in packages

  -v, --verbose...
          Use verbose output (-vv very verbose/build.rs output)

      --color <WHEN>
          Coloring: auto, always, never

          Require Cargo.lock and cache are up to date

          Require Cargo.lock is up to date

          Run without accessing the network

      --config <KEY=VALUE>
          Override a configuration value (unstable)

  -Z <FLAG>
          Unstable (nightly-only) flags to Cargo, see 'cargo -Z help' for details

          Timing output formats (unstable) (comma separated): html, json

          Outputs a future incompatibility report at the end of the build (unstable)

  -h, --help
          Print help information (use `-h` for a summary)

PEP 660 Editable Installs

Maturin supports PEP 660 editable installs since v0.12.0. You need to add maturin to build-system section of pyproject.toml to use it:

requires = ["maturin>=0.14,<0.15"]
build-backend = "maturin"

Editable installs right now is only useful in mixed Rust/Python project so you don't have to recompile and reinstall when only Python source code changes. For example when using pip you can make an editable installation with

pip install -e .

Then Python source code changes will take effect immediately.

Import Hook

Starting from v0.12.4, the Python maturin package provides a Python import hook to allow quickly build and load a Rust module into Python.

It supports pure Rust and mixed Rust/Python project layout as well as a standalone .rs file.

from maturin import import_hook

# install the import hook with default settings
# or you can specify bindings
# and build in release mode instead of the default debug mode

# now you can start importing your Rust module
import pyo3_pure