skillfed

maturin-import-hook

Import hook to load rust projects built with maturin

maturin-import-hook v0.3.0 99.1K downloads/30d#13,040 on PyPI19
Permissive license Active released

What it is and what it does

Maturin Import Hook is a Python import hook that intercepts imports of Rust projects built with maturin and automatically recompiles them if their source has changed. It bridges the development experience gap between Python and Rust by making Rust changes take effect on import, just like Python code does. The hook works in two modes: it can rebuild editable-installed maturin packages on import, or compile standalone .rs files into temporary projects in a build cache. This reduces friction when working on mixed Python/Rust codebases by eliminating manual rebuild steps.

The package integrates into Python's import system and can be activated either globally or per-script by calling maturin_import_hook.install(). It requires maturin to be installed separately and depends on filelock and tomli for its own operation. The hook also supports importlib.reload() for recompiling projects during development and includes a CLI for managing the build cache and installation state.

Use it for:

  • Developing a Python package with Rust extensions where you want Rust changes to take effect immediately on re-import without manual rebuilds.
  • Writing standalone .rs files as importable modules in a Python project to test or prototype Rust code without a full package structure.
  • Iterating on performance-critical Python functions by rewriting them in Rust and testing them in the same development loop.
  • Managing a monorepo with multiple editable-installed maturin packages that need to rebuild on demand during active development.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Automatically rebuilds Rust components in maturin projects during Python imports, eliminating the need to manually recompile when Rust code changes.

Yes, if you are actively developing mixed Python/Rust code with maturin. The low install friction, permissive licensing, active maintenance, and zero known vulnerabilities make it a safe choice. The import hook genuinely reduces development friction by automating rebuilds. Not necessary if you are only consuming pre-built Rust extensions or not using maturin.

Install

maturin-import-hook on PyPI

pip

pip install maturin-import-hook

uv

uv add maturin-import-hook

poetry

poetry add maturin-import-hook

Installing maturin-import-hook

Before you install

Low friction install with only filelock and tomli as runtime dependencies. Actively maintained with recent releases; last commit on 2026-07-11.

License in practice

Dual-licensed under Apache 2.0 or MIT at your option—both permissive licenses with no copyleft obligations, making it safe for commercial and proprietary projects.

Quickstart

pip install maturin_import_hook

import maturin_import_hook
maturin_import_hook.install()

# Rust changes now rebuild automatically on import

Requires maturin to be installed separately; Python >= 3.9 required.

Verify before relying

  • Whether the hook works with all maturin project configurations or has known limitations with certain build setups.
  • Performance impact of automatic rebuilds on large Rust codebases during development.
  • Compatibility with different Python virtual environment managers beyond standard venv.

Package facts

License not declared (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 2 — filelock, tomli
Maintenance actively maintained — 432 days since the last release
Last repo commit
First released
Downloads 99,072/month — #13,040 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: maturin_import_hook-0.3.0-py3-none-any.whl

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: RustTopic :: Software Development :: Build Tools

Tags

maturin import hookrust python importautomatic rust rebuildmaturin development workflowmixed python rust developmentpyo3 import automationrust file import python
rust-python-interopdevelopment-workflowimport-hook

More Build Tools packages