created_at2020-12-28 07:16:44.946812
updated_at2021-09-28 03:24:18.710619
descriptionA cargo plugin to make it easier to write and convert crates into Python extension modules.
Erica Stith (rexlunae)




Cargo extension to make a Rust crate into a hybrid Python/Rust library.

This crate is based on PyO3


You will need:

setuptools_rust can be installed with pip:

pip install setuptools_rust

And toml can be installed like this:

pip install toml


From github:

git clone
cd cargo-pyinit
cargo install --path .

From cargo:

cargo install pyinit


pyinit can only be used to create or modify a library crate.

From inside a source directory:

cd my-create-directory
cargo pyinit

If the directory is already a cargo crate, it will convert it into a hybrid crate suitable for use with python. If the directory is empty, it will create a new library crate with the same name as the directory it's in.

From outside a directory:

cargo pyinit crate-name

This will create the directory with the given name, if needed, and either create a new crate or modify an existing crate.

Unlike the example code for PyO3, pyinit creates a new file ( that becomes the base of the library, which imports everything from the old (or whatever it was previously called). This separates the Python interface definition somewhat, but it also means that some items that are only allowed at the top level of the crate such as feature flags be moved manually. When creating a new crate, the result will work out of the box with either cargo build or the Python setup tools, however, if you are modifying an existing crate, you will probably have to spend some time manually moving things into the from your You will need to build the Python interface manually as well. This does not happen automatically.

The resulting hybrid crate has a, which can be installed in Python with either python develop for a development version, or python install for release. You can also use pip install .

Commit count: 22

cargo fmt