Python package setup for adding some additional rust functions
Project description
Python package with Rust
Python package with some functions in Rust using PyO3 and Maturin. Maturin was made for all Rust python packages. How mixed packages work is mentioned in the README. Some fiddling has to be done with the project structure, Cargo.toml, pyproject.toml to get everything right. It should be possible to:
- test the package locally (after building the Rust part)
- buid the package with both Rust and Python
Development Setup
Install all dependencies including Maturin.
# using conda environments here
conda env create -f environment.yml
conda activate lutz
There is a python package python/lutz/
and a Rust library rust/lib.rs.
In lib.rs a python module is implemented which is referenced in
Cargo.toml in lib.name
.
Cargo.toml also defines package name and version number.
# build rust library
maturin develop
The library is build and a resulting _lib.*.so
file is placed in python/lutz.
This is defined in pyproject.toml under [tool.maturin]
.
From now on rust functions can be imported as private _lib
.
I wrote a wrapper in python/lutz/rust.py.
Note .vscode/settings.json and vscode.env is setup for being able to import lutz from the integrated python terminal and Jupyter notebooks, as well as tell pylint how to import lutz.
Tests
Using pytest python test suite.
_lib.*.so
in python/lutz/ must have been built before
(maturin develop
).
PYTHONPATH=./python pytest tests
Build and release
Maturin builds the project as defined in pyproject.toml
into a .whl
.
This will only create a wheel for this architecture, platform, and python version.
# release for optimizations
maturin build --release
Maturin can also be used for publishing packages.
maturin publish
builds with --release
and publishes (pypi.org by default).
This will upload a wheel and a source distribution.
maturin publish
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for lutz-0.1.2-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef97f65a3e0164e247d003a8235df0e4702f6f3f79ee7f52f88ebe26e6a0aeb4 |
|
MD5 | d2ac1a897b28c4796b2580b9f3e0e824 |
|
BLAKE2b-256 | 41132b01a9363676b4ae2e2c18386c703802ef4f54ea56677d469a4a7e2ad775 |