Questions tagged [pyo3]

Used for questions related to the Rust library pyo3.

pyo3 is a Rust library that provides bindings for Python.

161 questions
2
votes
1 answer

PyO3-Maturin publish command doesn't upload Readme and License to PyPi

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 │ └──…
Adam
  • 743
  • 1
  • 6
  • 11
2
votes
0 answers

pyo3 - Getting the result of async fuction

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…
alfex4936
  • 311
  • 3
  • 10
2
votes
1 answer

Rust libraries made with PyO3 and rust-cpython won't import when running pytest

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…
Anton Shpigunov
  • 184
  • 2
  • 8
2
votes
1 answer

Rust showing expected trait object `dyn Future`, found opaque type when passing function as a param

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…
Sanskar Jethi
  • 544
  • 5
  • 17
2
votes
1 answer

PyO3 - Deriving FromPyObject for Enums

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…
interrupt0
  • 25
  • 5
2
votes
1 answer

Pass List of Python Dictionaries to Rust Function PyO3

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…
cpage
  • 119
  • 6
  • 27
2
votes
1 answer

Pass list of lists as argument to Rust from Python using PyO3

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 writing bindings for a…
Casper S
  • 118
  • 9
2
votes
1 answer

How can I create a destructor method using pyo3 in Rust when creating a Python class?

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 { …
John
  • 2,551
  • 3
  • 30
  • 55
2
votes
0 answers

How can I make a Rust struct that modifies its own value in a different thread?

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…
John
  • 2,551
  • 3
  • 30
  • 55
2
votes
1 answer

Using pyo3 pyclass on a rust struct that contains types from a different crate

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…
sam
  • 1,005
  • 1
  • 11
  • 24
2
votes
1 answer

Rust Numpy library - iterate by rows: unable to build a NpySingleIterBuilder::readwrite that returns rows instead of single values

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…
2
votes
1 answer

Using Maturin when external library is needed

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…
Genarito
  • 3,027
  • 5
  • 27
  • 53
2
votes
1 answer

TypeError in Python using PyAny in reflected numeric emulator (e.g. __radd__) for a Rust pyo3 pyclass struct

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…
Jules SJ
  • 430
  • 2
  • 8
2
votes
1 answer

PyO3 - passing class extending another class as a function argument

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 { …
Damian
  • 178
  • 11
2
votes
0 answers

How to efficiently convert Python structures to serde_json::Value?

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…
Stranger6667
  • 418
  • 3
  • 17