Questions tagged [pyo3]

Used for questions related to the Rust library pyo3.

pyo3 is a Rust library that provides bindings for Python.

161 questions
1
vote
0 answers

Problem with _ctypes extension when loading Numpy from Rust with PyO3

I am trying to use numpy from Rust using pyO3, all inside a conda environment. To get pyO3 to link, I installed the GCC toolchain using conda as well. I can do simple stuff now like displaying sys.path. However, when I try to import numpy, like…
1
vote
2 answers

How can actix Actor have PyO3 Python?

I'm trying to create Actix Actor which has PyO3 Python interpreter & Py objects. Question is what is the correct way to create python interpreter actor? I think err caused by Actor trait defined…
0
votes
1 answer

How to speed up Rust clone method in my custom struct?

I have struct in Rust with following fields and their types: five i8 six f32 one bool one Vec of size 4 one Vec> of size 4x20x7 one Vec of size 4x20 one HashMap with 4 keyes one Vec<(i8, i8)> of size varing from 0 to 30 My…
0
votes
0 answers

Generate Python Documentation from .pyi stub

I Have a Pyo3 project written in rust where I'm generating a python package. To get IDE typings, I've created a .pyi stub, with relevant docstrings. However, I notice that the docstrings on the actual python objects are empty. This isn't a huge…
Potatoman
  • 23
  • 3
0
votes
1 answer

returning PyBytes from async function in pyo3 and pyo3_asyncio

I have the following working implementation for reading bytes from a datachannel and returning the bytes as a list in the python interop: fn read<'a>(&self, py: Python<'a>) -> PyResult<&'a PyAny> { let mut dc = self.datachannel.clone(); …
Kevin
  • 3,096
  • 2
  • 8
  • 37
0
votes
1 answer

How to include a struct with Rc in a Pyo3 #[pyclass]?

I attempted to add #[pyclass] to a struct that includes Rc, but I encountered the following error. error[E0277]: std::rc::Rc cannot be sent between threads safely Here's my source code: struct MyStruct { name:…
0
votes
1 answer

How to Pickle / deepcopy Python class created with maturin?

I've been working on integrating rust code into python using PyO3 and Maturin. I've successfully written my Rust class and gotten most of the functionality to work, however I haven't been able to successfully deepcopy the object. I've tried…
wfjohns1
  • 31
  • 2
0
votes
1 answer

How to modify Python list of custom rust objects from within Rust with PyO3?

I'm new to Rust and I have a problem. I have list in Python. It is a list of objects implemented in PyO3 Rust. I want to pass it to a function to make some changes to the elements. This is minimal reproducible example: use…
0
votes
0 answers

Higher-order/chaining functions in rust using pyo3

I'm having issues with attempting to call functions from within other functions in pyo3 with rust. When I try, and change the output type to a pyresult to get the functions to chain together, I just end up with a whole host of other errors and I was…
aqollo
  • 13
  • 3
0
votes
0 answers

PyO3 unable to find/call Python function from within a Rust application

I have the beginning of a GUI application written in Rust. I'm using the Py03 crate to run a python function inside my Rust app. I have my python function (test_func) inside a file "test_funcs.py" and this file is located in the same directory as my…
Beatdown
  • 187
  • 2
  • 7
  • 20
0
votes
0 answers

Using pyo3 and maturin for Python bindings. How to structure it?

For an existing library, what is the best (or at least good) way to structure the project when creating Python bindings via pyo3 / maturin ? So far I figure I can either just annotate all the structs and impls with #[pyclass] and #[pymethods]…
FISR
  • 13
  • 1
  • 5
0
votes
1 answer

ImportError: PyO3 modules may only be initialized once per interpreter process

I am working on a Django project which includes DRF. The application is dockerized. Everything was working fine then suddenly I got the following error in my logs and I am completely clueless how it arrived patients | [uWSGI] getting INI…
Muhammad Safwan
  • 869
  • 7
  • 12
0
votes
0 answers

Check the type of an input in pyO3 Rust

Could someone give a full/working example of a function in pyO3 that takes a single input, and returns true/false depending on whether the input has type scipy.sparse.csr_matrix? I'm aware that pyO3 has is_instance, but that seems to require having…
GHPR
  • 45
  • 6
0
votes
0 answers

Rust package compiled with Maturin for use in Python causes significant runtime overhead compared to pure Rust

I am currently attempting to gain a speed-up for some computationally expensive parts of my Python code by instead rewriting them in Rust with PyO3 and using Maturin to create a Python package. I noticed that the Rust implementation was more than 3…
0
votes
1 answer

How to use reference to python int from rust method with pyo3?

How does one unpack a python integer as a reference from a rust class method? I'm trying to expose a rust struct to python but the interpreter complains about the reference to the i32. This is the code: #[pyclass] pub struct DataMap { entries:…
songololo
  • 4,724
  • 5
  • 35
  • 49