Skip to main content

No project description provided

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:

  1. test the package locally (after building the Rust part)
  2. 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

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

Publishing

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

lutz-0.1.0.tar.gz (17.7 kB view hashes)

Uploaded Source

Built Distribution

lutz-0.1.0-cp39-cp39-manylinux_2_34_x86_64.whl (200.2 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.34+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page