I believe it should be possible to distribute Python packages as Rust crates. If you have actually done this and can point me at an open source proof of concept, I would be very grateful for a link.
@gvwilson at work i do maintain a package that's primarily consumed in python but written in rust. python's setuptools-rust has first class support for building rust and using rust wheels.
maturin itself is a good example
https://github.com/PyO3/maturin
and the readme has pointers to some other python packages which are written in rust.
@prozacchiwawa thanks, but what I'm after is Python code distributed as a Rust crate rather than Python modules that include Rust - basically, if we were starting from scratch, could Python piggyback package distribution on top of cargo/crates?
@gvwilson ahh apologies, i misunderstood what you were asking.
@prozacchiwawa @gvwilson I think that’s the opposite way round of what Greg’s asking?
I am reading this the other way around: shipping Python code as a Rust crate so it can be consumed in Rust? Maybe I got it all wrong as it sounds odd. I think PyO3 also lets you call Python from Rust so could likely do it, but I know of no tool that helps with the distribution aspect..
See "using Python from Rust"
https://pyo3.rs/v0.15.1/
@faassen @gvwilson yes pyo3 lets you consume python code from rust as well, although it can take a bit of doing to get the system paths right so the python library finds what's intended (especially macos does this differently, and needs special handling).
apologies, i misunderstood the question as asking about how to provide a python package using rust (and incidentally cargo) as opposed to python code via cargo itself.
@faassen @prozacchiwawa apologies for the lack of clarity in the original post - I want to ship Python code as a crate to be consumed by Python.
Python code wrapped in a Rust crate and then re-exposed to Python? Instead of using Python packaging?
I think PyO3 can do most of it as it can go both ways, but I am really intrigued about the use case? As passing Python objects through a Rust layer only to turn them back seems to be just overhead, though I am pretty sure you can keep it relatively low by passing PyObjects along
@gvwilson for what purpose? (curious, don’t have pointers)