I've a built a rust-python project and published it to PyPi using Maturin.
The project is structured like the example on the maturin readme with the addition of the License file:
my_project
├── Cargo.toml
├── my_project
│ ├── __init__.py
│ └──…
I'm trying to export rust async function to python.
And this is how I want to use in my python file.
from rust_lib import get_weather
async def call_me():
weather = await get_weather()
print(weather.current_tmp)
In Rust, I did…
While following various tutorials on compiling Rust libraries for further import from Python (I've tried both PyO3 and rust-cpython), I've been able to build a simple libary and successfully import it from my main.py and interactive Python…
use std::io::prelude::*;
use std::net::TcpListener;
use std::net::TcpStream;
use std::time::Duration;
// pyO3 module
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;
use std::future::Future;
#[pyfunction]
pub fn start_server() {
let listener…
I'm trying to build a Python package from Rust using PyO3 (version: 0.13.2). Right now I'm stuck trying to get the conversion working for enums. I have a simple enum like so:
#[derive(FromPyObject)]
#[derive(Copy,Clone,PartialEq,Eq)]
enum Direction…
I am trying to write a function in rust that I can call from python that accepts a list of dictionaries (think pandas dataframe-like data) and access those key, values from rust. How can I accomplish this? I am using pyo3. Do I need to define a…
I'm trying to pass a list of lists from Python to Rust using Py03. The function I'm trying to pass it to has this signature:
pub fn k_nearest_neighbours(k: usize, x: &[[f32; 2]], y: &[[f32; 3]]) -> Vec
I'm using pyo3 in Rust to create a Python module.
I can create a class, and a constructor with:
#[pyclass]
struct MyClass {
i: u8,
}
#[pymethods]
impl MyClass {
#[new]
fn new() -> PyResult {
…
I'm making a Python module, written in Rust, using pyo3, that will:
Run its own thread
Read an input pin on a Raspberry Pi, counting how many times the state changes
Let Python query the counter
So far, my code looks like this:
use…
I have a rust struct that uses the pyo3 pyclass macro to allow using in python. This works fine for simple structs but if I have a struct that contains a type from a different library it becomes more difficult.
Example:
use…
I am trying to iterate by rows over a Numpy Array. The array is accessed thru PyO3 and I think the library acess to the underlying C object just fine but I can't seem to find the reference for a more complex SingleIteratorBuilder that helps me…
I'm trying to make a Python package from a Rust Crate I'm making. The problem is that I need the RGSL crate which needs libgsl0-dev installed in the system.
I'm trying to publish using Maturin which uses Manylinux Docker image to build everything…
I've created a Rust library for python using pyo3. This contains a pyclass struct that implements several of PyNumberProtocol methods like __add__, __sub__, etc... to allow python operators like + and - to work on the class. I'm using PyAny as the…
I have a library in Rust and I want to be able to use it from Python. So I can do the bindings using PyO3.
Let's suppose that I have a following library in Rust:
pub trait Animal {
fn make_sound();
}
pub struct Dog {}
impl Animal for Dog {
…
Context
I implemented a Rust library for JSON Schema validation which operates with serde_json::Value instances. Now I want to use it from Python and considering PyO3 as my primary choice for connecting them. Python values should be converted to…