Skip to main content

Maturin Import Hook

A python import hook to automatically rebuild maturin projects and import stand-alone rust files.

Using this import hook reduces friction when developing mixed python/rust codebases because changes made to rust components take effect automatically like changes to python components do.

The import hook also provides conveniences such as importlib.reload() support for maturin projects.

Documentation can be found at maturin.rs.

Usage

After installing maturin, install the import hook into a python virtual environment with:

pip install maturin_import_hook

Then, optionally make the hook activate automatically with:

python -m maturin_import_hook site install

This only has to be run once for each virtual environment.

Alternatively, put the following at the top of each python script where you want to use the hook:

import maturin_import_hook

# install the import hook with default settings.
# this call must be before any imports that you want the hook to be active for.
maturin_import_hook.install()

# when a rust package that is installed in editable mode is imported,
# that package will be automatically recompiled if necessary.
import example_maturin_package

# when a .rs file is imported a project will be created for it in the
# maturin build cache and the resulting library will be loaded.
#
# assuming subpackage/my_rust_script.rs defines a pyo3 module:
import subpackage.my_rust_script

Once the hook is active, any import statement that imports an editable-installed maturin project will be automatically rebuilt if necessary before it is imported.

CLI

The package provides a CLI interface for getting information such as the location and size of the build cache and managing the installation into sitecustomize.py. For details, run:

python -m maturin_import_hook --help

Debugging

If you encounter a problem, a good way to learn more about what is going on is to enable the debug logging for the import hook. This can be done by putting the following lines above the import that is causing an issue:

# configure logging if you haven't already (make sure DEBUG level is visible)
logging.basicConfig(format="%(name)s [%(levelname)s] %(message)s", level=logging.DEBUG)
maturin_import_hook.reset_logger()

import some_package

License

Licensed under either of:

at your option.

Metadata

Release files for maturin-import-hook 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for maturin-import-hook 0.3.0
File Size Uploaded
maturin_import_hook-0.3.0.tar.gz 30.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for maturin-import-hook 0.3.0
File Interpreter ABI Platform
maturin_import_hook-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 61.6 kB

Release files / maturin_import_hook-0.3.0.tar.gz

Download URL maturin_import_hook-0.3.0.tar.gz
Size 30.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cdd51ce267663c437c4aea1bfd5f7ee5884b54a9d866ea924227d68d758bbba2
BLAKE2b-256 checksum
How to use checksums
75a13b007a4132265d5da19096d6835cd4c7e9908afb9156afb96d19ff190f39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 8, 2025.

Transparency log

Release files / maturin_import_hook-0.3.0-py3-none-any.whl

Download URL maturin_import_hook-0.3.0-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f5d20b4bc3056d84170dc08fe655160421b28d2b5128b48f55312315cdbb2cfe
BLAKE2b-256 checksum
How to use checksums
9f550c17a1fccec90dffbb1d904d7ddb7971e4e95f994c6264637e8fe66a5b86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 8, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page