From bf4a65e50373d31f4bba289388a642353f2b8495 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 6 Dec 2021 23:17:19 +0800 Subject: [PATCH] Document Python import hook in user guide --- guide/src/develop.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/guide/src/develop.md b/guide/src/develop.md index 01ed32e47..0d286745b 100644 --- a/guide/src/develop.md +++ b/guide/src/develop.md @@ -64,3 +64,25 @@ pip install -e . ``` Then Python source code changes will take effect immediately. + +## Import Hook + +Starting from v0.12.4, the [Python maturin package](https://pypi.org/project/maturin/) 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. + +```python +from maturin import import_hook + +# install the import hook with default settings +import_hook.install() +# or you can specify bindings +import_hook.install(bindings="pyo3") +# and build in release mode instead of the default debug mode +import_hook.install(release=True) + +# now you can start importing your Rust module +import pyo3_pure +```