This crate was written to test with the
python-with-rust
command line application
While this project is by no means extensive, it's meant to at least serve as a starting point for those looking to improve their Python applications by writing and implementing custom modules in Rust.
This module utilizes the command line tool maturin
and the pyo3
crate to create Python functions, which in turn can be imported into and called from regular Python applications.
The process of creating a new Python-compatible Rust module is relatively straightforward:
- Install the
maturin
command line tool ->pipx install maturin
- Create a new module project set to use
pyo3
->maturin new -b pyo3 some-module
- Open up
lib.rs
and define a couple functions annotate with thepyfunction
attribute - Add the new functions to a separate function declaration annotated with the
pymodule
attribute
After getting your module all put together, it's time to upload it to a version control system (i.e Github
) to allow for easy installing and implementation of the package in some Python code!
Once your code is available on Github
( or whatever platform you decided to use ), all that's left to do is actually install it for use in a Python project. This can be achieved by using pip
just like you would any other Python package, with one caveat; you'll need to tell pip
that it's installing a package from version control by passing a special argument to the command:
pip install git+https://github.com/<username>/<repo>@main
NOTE: It's important that you include the
@main
at the end of the command to ensure you're installing the most current version of your package.
For more detailed information on how to develop a Rust-Python project from start to be, be sure to check out Parts 1 & 2 of Make your Python Faster with Rust
on Medium