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

How do I ensure memory is properly freed when passing PyBytes from Rust to Python?

I have a Rust library using PyO3, and one of my functions looks like this: #[pyfunction] pub fn my_func<'a>(py: Python<'a>) -> PyResult<&'a PyBytes> { let my_data: Vec = do_stuff(); // very large data here, >1GB let result =…
user655321
  • 1,572
  • 2
  • 16
  • 33
0
votes
1 answer

rusqlite and pyo3 PyResult handling errors

I'm attempting to open and write to a database in a Rust library I will call from python, with the help of pyo3. If an error occurs, I would like to raise an exception that can be caught in the calling Python process, but I'm having difficulties…
Simen Russnes
  • 2,002
  • 2
  • 26
  • 56
0
votes
1 answer

How can I make my PyO3-based libraries more portable across Python versions?

I have a library that I've created with PyO3 on my system using Python 3.5.2. The .so file links to the corresponding libpython3.5m file: $ ldd my_library.so linux-vdso.so.1 => (0x00007ffffc823000) libpython3.5m.so.1.0 =>…
user655321
  • 1,572
  • 2
  • 16
  • 33
0
votes
1 answer

How to execute floor division in Python code embedded in Rust code with PyO3?

I'm trying to inline Python code in Rust, but it fails when the Python code has the operator for floor division // which is ignored as if it were a Rust comment. For instance: #![feature(proc_macro_hygiene)] use inline_python::python; fn main() { …
Clonk
  • 2,025
  • 1
  • 11
  • 26
0
votes
0 answers

Recommended way to test Python extensions written in X language

I have some class A that is part of a Python extension I wrote in Rust using PyO3. class A is imported and used as is, as well as being as being subclassed in my Python code as part of a larger Python package. It's not meant to be an independent…
kentwait
  • 1,969
  • 2
  • 21
  • 42
0
votes
1 answer

Calling from Python Rust function with kwargs fails

I am struggling to get kwargs to work. I understand that just like #[args(args="*")] is for args, #[args(kwargs="**")] is for kwargs. However when I pack the following using pyo3-pack and try to call test1 with any arguments I get the error…
user7810882
  • 223
  • 1
  • 4
  • 14
0
votes
1 answer

What is the best practice to follow in order to use Python to call functions from inside a Rust program?

I want to implement a system which consists of a Python UI and some Rust datastore and functions. The user executes the python code which in turn executes the Rust program in a subprocess. I want the Rust program to run in the background, waiting…
Craftrac
  • 753
  • 1
  • 7
  • 13
-1
votes
1 answer

How to return a PyTuple in rust using pyo3?

I want a function that simply creates and returns a tuple as an example. Basic template starting code (maturin new) looks like: use pyo3::prelude::*; /// Formats the sum of two numbers as string. #[pyfunction] fn sum_as_string(a: usize, b: usize)…
mathtick
  • 6,487
  • 13
  • 56
  • 101
-1
votes
1 answer

Publish a library for Python made with Rust to pypi

Is this possible? After some research, it seems that the library setuptools-rust can be used for easy distribution, but it looks like the user also needs this library setuptools-rust. Is there any way to make the installation work without…
tasuren
  • 181
  • 1
  • 7
-2
votes
1 answer

pyo3 import local file

I created 2 files that have the same function. One is named test1.py and the other test2.py. I try to import test1 that imports test2. Rust throws this error. How can i import relative paths. Id prefer not to change the python code, since i want to…
-2
votes
1 answer

PyContextProtocol example for pyo3?

In the __enter__ method I want to return an object which is accessible in Rust and Python, so that Rust is able to update values in the object and Python can read the updated values. I would like to have something like…
Martin Bammer
  • 537
  • 7
  • 19
1 2 3
10
11