Questions tagged [pyo3]

Used for questions related to the Rust library pyo3.

pyo3 is a Rust library that provides bindings for Python.

161 questions
0
votes
0 answers

Pyo3 library using sdl2

I was gonna create a Pyo3 library which implements some RL environments. I had been using Pyo3 for other tasks. I was gonna use also SDL2 rendering, however it gives me an error. #[pyclass] pub struct FirstEnv { pos: f32, renderer:…
0
votes
0 answers

Can I call an IO-bound Python function from multiple Rust threads concurrently?

I have a Python function that can be slow, so I need to be able to run that function concurrently. If I were running the Python script directly, I'd simply create multiple threads and so I would be able to easily run that function concurrently. I…
yolapo
  • 19
  • 1
0
votes
0 answers

Rust-python bindings; assessing it from a main python package which uses the bindings

Many python packages have their performance-critical parts written in Rust and binded to python using, e.g. pyo3. Within the same repo, both .py and .rs files residing in different directories, e.g. in Polars, the rust parts are in polars and the…
Jim
  • 450
  • 2
  • 10
0
votes
0 answers

Extracting an associated type from a reference, without specifying a lifetime

I'm using a trait to define an associated type. pub trait SharedType{ type Item; } There are cases where I need to implement this trait on a reference &T. However, in these situations I'd like to auto-implement SharedType on a wrapper struct pub…
GHPR
  • 45
  • 6
0
votes
1 answer

Retrieve a #[pyclass] from an attribute of an arbitrary PyAny

Let us say I have the following Rust struct which becomes a Python class: #[pyclass] struct MyRustClass { foo: i32 } #[pymethods] impl MyRustClass { #[new] fn new(foo: i32) { MyRustClass { foo } } } This class is made…
Darren
  • 1,774
  • 4
  • 21
  • 32
0
votes
0 answers

Py03 - creating derived class not via new (ctor) method

`I have base class and derived class. Base class ctor - works and everything ok, Ive added "create" static method on the dereived class ( which has the same exactly code and return value . For some reason ctor compiles and work and the derived class…
0
votes
1 answer

How to iterate over vector of pyclass objects in rust?

I am using maturin and I am trying to implement the method get_car() for my class. But using the following code use pyo3::prelude::*; #[pyclass] struct Car { name: String, } #[pyclass] struct Garage { cars: Vec, } #[pymethods] impl…
Prokie
  • 66
  • 7
0
votes
0 answers

pyo3 Troubles with `inspect.signature` method

I have a rust struct with which I had implemented python's magic methods __iter__, __next__, and __call__. #[pyclass(name = "PyNRICContainer")] #[derive(Debug)] #[pyo3(text_signature = "(cls, value, values)")] pub struct PyNRICContainer { …
Jim
  • 450
  • 2
  • 10
0
votes
2 answers

How do I return rust iterator from a python module function using pyo3

Its not like I am not able to return any rust iterators from a python module function using pyo3. The problem is when lifetime doesn't live long enough! Allow me to explain. First attempt: #[pyclass] struct ItemIterator { iter: Box
iamsmkr
  • 800
  • 2
  • 10
  • 29
0
votes
0 answers

How to run tests only in rust file that belongs to PyO3 package?

I have a Rust package which is basically a PyO3 extension. In there I have two files, lib.rs, that is creating a python module and doing conversions from and into Rust types, and parsing.rs which is pure Rust code that I'm wrapping. Now the issue I…
Daniel
  • 980
  • 9
  • 20
0
votes
1 answer

Get Python ID as a number for Py03 PyAny object in Rust

I'm using Py03 to build a python module in Rust. I have a class in Rust which accepts a PyAny to refer to an object in Python. As part of the hash function for the rust class, I want to use the Python ID for this object in the hash function in Rust…
David Chanin
  • 533
  • 6
  • 17
0
votes
1 answer

Fuction which returns data loaded with Pyo3 - cannot return value referencing temporary value

I am trying to implement method which uses Pyo3 loads numpy array. use ndarray::{array, ArrayView, Ix2}; use numpy::PyArray2; use pyo3::types::IntoPyDict; use pyo3::{PyResult, Python}; pub fn load_2d_vec<'a>() -> ArrayView<'a, f32, Ix2> { // …
0
votes
0 answers

How to append to list in python module written in rust?

I am writing a python model for heavy calculations in rust using the pyo3 bindings. However, for a rust struct with a variable containing an empty list I cannot append to that variable in python. Does anybody know how to do this? See below for a MWE…
westr
  • 569
  • 5
  • 17
0
votes
0 answers

How to specify to pyo3 the virtualenv to use in a rust project?

I need port some python code in my rust project (calling python from rust). I am writing an app in rust that in a small part needs to import a module written in python. This is my project…
al3x
  • 589
  • 1
  • 4
  • 16
0
votes
0 answers

Is there a way to change the submodule path for a partially python pyo3 rust module

If I have a project like this: project / __init__.py src / lib.rs Cargo.toml ... In the python part (__init__.py), I have to import rust code via: from .project import * Is there a way to change the name of the submodule used or is there a…
Middledot
  • 82
  • 1
  • 7