I have 2 pyclasses Block and BlockGroup.
#[pyclass]
struct Block {
start: i32,
stop: i32,
}
#[pyclass]
struct BlockGroup {
blocks: Vec
}
I'm new to PyO3 and I have read the documentation about garbage collection but I don't…
I have a function that accepts a Python list. I expect the list to be made of strings. How do I extract them?
fn f(list: &PyList) -> PyResult {
for obj in list.iter() {
let rust_string = PyString::from_object(obj, "ASCII",…
I'm following the PyO3 Guide and have so far got to chapter 2, Python modules. OS is W10.
I am entering all commands using the CLI outside Eclipse and just using the latter to edit files. NB the Rust add-on, Corrosion, provides some "intellisense"…
I'm trying to create a Python package with Pyo3 & Rust.
in one of my functions, I'm trying to return a tch::Tensor type though not sure how to transform it so Python will be familiar with it.
here's what I've tried so far:
use pyo3::prelude::*;
use…
I have two structs: Struct and InnerStruct. Struct has two methods: modify_object that uses modify_object_inner. Rust implementation of modify_object_inner doesn't matter because I want to implement this method in class that will inherit after my…
I have an api written in Rust but since a lot of colleagues only know Python I am trying to make it possible to build data pipelines in Python within the rust program.
The idea would be make a Python interface to the rust code and vice versa. Then…
I have re-written some Python into Rust using pyO3. I have a situation where my Rust code can panic somewhere in a third party Rust library I use. The simplest thing for me would be to catch that panic in Python-land and fall back to the slower (but…
I'm trying to build a Python package from Rust using PyO3. Right now I'm stuck trying to return enums Rust type to Python.
I have a simple enum like so:
pub enum Lang {
Deu,
Eng,
Fra
}
And in lib.rs
#[pyfunction]
fn…
I'd like to add hidden methods to pyo3 class methods implementation which will be invisible for Python.
Example:
#[pyclass]
pub struct SomeItem;
#[pymethods]
impl SomeItem {
#[new]
pub fn new() -> Self { // visible for python constructor
…
Motivation
This question is framed in terms of a specific example, for concreteness, but it's part of a much bigger question of how to return objects in pyo3, generally.
Problem
I'm writing a python module with a Rust backend using PyO3.
I'd like to…
Using PyO3, from a long-running Rust application I want to be able to call some functions many times. Before that I need to import a few modules. How can I do the imports just once and then re-use the PyModules from other threads that call the…
I have the following class structure defined in a Rust PyO3 Extension:
#[pyclass(subclass)]
struct Parent {
foo: i32
}
#[pyclass(extends=Parent)]
struct Child {
bar: i32
}
Then in Python, a pure python class contains an attribute which can…
Here's a reduced form of problem: I have a trait
pub trait GetIter {
type IntoIter: IntoIterator;
fn get_iter( &self ) -> Self::IntoIter;
}
There are several use cases where I can implement GetIter on a reference &'a T, but not…
A few days ago I came across by inline-python, which uses rust macro system to make developers able to write python code in rust, and uses PyO3 to do so, Im wondering is there a way to easily import packages of PyPi, without including their file in…
I am trying to implement a cache for the private variable of any python class.
Let's suppose I have this:
#[pyclass]
struct ClassA {
pv: Py, // GIL independent type, storable in another #[pyclass]
field_a:…