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 compiles & imports correctly but exits without any error message when a function is run

As soon as my python module calls a rust function, it exits without any output and ignores try/except blocks. My code is something like this: python: def call_rust(some_bytes: bytes): print("debug") val = rust_function(some_bytes) …
Middledot
  • 82
  • 1
  • 7
0
votes
1 answer

Can you write part of a library in rust (pyo3) but the rest in python?

I want to write part of a python module in rust (with PYo3) but also partly in python, so something like... src/utils.rs: use pyo3::prelude::*; #[pyfunction] fn sum_as_string(a: usize, b: usize) -> PyResult { Ok((a +…
Middledot
  • 82
  • 1
  • 7
0
votes
0 answers

How is the thread pool managed when using Rayon and PyO3?

I am currently trying to speedup a python scientific code with the help of PyO3. Until now, numba's @jit has been doing wonders, but some routines are impossible to parallelize. I decided to turn to Rust and Rayon which provide the tools to…
Quettle
  • 23
  • 4
0
votes
1 answer

What are the differences between these 4 methods of returning `bytes` from Rust to Python using `pyo3`?

I'm new to pyo3 and a beginner in Rust. What I'm trying to do is to return from Rust slice to Python bytes. I read both about the type conversion and memory management in the pyo3 documentation, but I still feel a bit lost. This is what I have right…
se7entyse7en
  • 4,310
  • 7
  • 33
  • 50
0
votes
1 answer

rust: py03 how to get reference to struct member

How do I edit Header.a via Packet.Header.a? #![allow(dead_code)] use pyo3::prelude::*; #[pyclass] #[derive(Clone)] pub struct Header { #[pyo3(get, set)] a: u32, #[pyo3(get, set)] b: u32, } #[pymethods] impl Header { #[new] …
raviv
  • 3
  • 3
0
votes
1 answer

Cargo run using PyO3

I'm working on a rust/python package using PyO3 and its working great from python after I run maturin develop. I can import my rust code into Python and run my functions as I expect. I would also like to still run my code from Rust though, and so…
dvreed77
  • 2,217
  • 2
  • 27
  • 42
0
votes
1 answer

How to use PyO3 custom module in production

I have created a custom module in rust and converted it to a python module using PyO3 binding. It works on a local machine using the hardcoded route, unlike other packages where it only has a name. I understand other packages are launched in PIP…
RevTpark
  • 65
  • 1
  • 8
0
votes
1 answer

How to create a PyArray to feed into method

I have a method foo with the following signature: pub fn foo(data: PyReadonlyArrayDyn) { ... } In my test I'm trying to create a test array to feed into foo pyo3::Python::with_gil(|py| { let vec = vec![1.0, 2.0, 3.0, 4.0]; py_array…
grmmgrmm
  • 994
  • 10
  • 29
0
votes
1 answer

How do I iterate over a pyo3 PyObject in Rust?

I have a pre-imported module that I'm calling a method with python gil, something like the following. Python::with_gil(|py| { let res = module.call_method1(py, "my_method", (arg1, arg2))?; }) This returns the rust object PyObject, however what…
AdmiralJonB
  • 2,038
  • 3
  • 23
  • 27
0
votes
0 answers

How to return a python variable from a python file to a rust file using pyo3

All the other questions on this forum tell you how to use rust to do something in python, but I want to do the opposite. I have a function in my main.py script that reads the user's input and stores it. I want to pass that information to a rust file…
Nick M
  • 73
  • 1
  • 8
0
votes
0 answers

Rust bindings for Python using pyo3

I am trying to generate Rust bindings for Python. Here is a simple example: use pyo3::prelude::*; struct MyClass { num: T, } impl MyClass { fn new(num: T) -> Self { MyClass { num } } } /// A Python…
Monica
  • 1,030
  • 3
  • 17
  • 37
0
votes
0 answers

Executing Python Async functions in Actix web sockets

I am trying to execute a python async function in an actix web socket. I was able to figure out how to execute a sync function and send the response back to the web socket. However, I am unable to do the same with the async functions. Here is my…
Sanskar Jethi
  • 544
  • 5
  • 17
0
votes
1 answer

PyO3 - prevent user submitted code from looping and blocking server thread

I'm writing a game in Rust where each player can submit some python scripts to the server in order to automate various tasks in the game. I plan on using pyo3 to run the python from rust. However, I can see an issue arising if a player submits a…
0
votes
0 answers

Is it possible to expose nalgebra matrix types to python via pyo3 in rust

I'm able to expose simple functions written in Rust to python using pyo3 but can see no way to expose complex "eigen" / matrix types. Does anyone know if this is possible? lib.rs extern crate nalgebra as na; use pyo3::prelude::*; use…
sbeskur
  • 2,260
  • 23
  • 23
0
votes
1 answer

Static lifetime annotation of a Pyo3-bound object

I'm trying to create a client using Rust and its Tokio runtime, and bind it to python using pyo3 and pyo3-asyncio. To bring this into a minimal example, let's say I want to have a Client class that connects to 127.0.0.1:1234 and has an echo method…
Jytug
  • 1,072
  • 2
  • 11
  • 29
1 2 3
10
11