Context of my question:
In pydantic's, you can define a CustomType, which is any python class with the following class method named __get_validators__(cls) defined. The objective is to have pydantic validate the input to the initialization of the…
Say I want to implement a native extension for deserializing a JSON object from a file. For an object with many keys, the first part of the execution time will be I/O, and the second part will be filling the dict up. I know it's safe to release…
I have a struct in Rust that works like a linked-list that I want to expose to Python. The struct has a parent field, which is a reference to a parent which is a struct of the same type. I need to wrap this in a Box, since Rust complains about…
I am new to Rust, and I am writing a library that creates background threads that listen and handle TCP communications. I want to store the latest n bytes for every TCP client and have Python to be able to fetch them. The way I am thinking about…
I'm a Rust newbie exploring language features with the possible result of recommending Rust as a replacement for C/C++ for our next FW iteration. One important topic is Python interop for unit testing and modeling. I've got this far exposing a Rust…
I created anaconda environment
$ python --version
Python 3.7.13
$ pip --version
pip 22.2.2 from C:\tools\miniconda3\envs\py37\lib\site-packages\pip (python 3.7)
In pyproject.toml I have requires-python = ">=3.7"
[build-system]
requires =…
Pylint will not recognize any of the functions from a PyModule that I created using PyO3 and maturin. All of the functions import and run fine in the python code base, but for some reason Pylint is throwing E1011: no-member warnings.
Below is a…
I am new to rust. I want to write a function which later can be imported into Python as a module using the pyo3 crate.
Below is the Python implementation of the function I want to implement in Rust:
def pcompare(a, b):
letters = []
for i,…
I implemented an algorithm in rust for speed, which is then built into a python module. Running the function is indeed much faster than the python implementation. But I noticed an interesting quirk: Running the function a lot of times (say, 1…
I have defined a few structs in my code and if a certain feature is enabled on the crate, I would like to generate Python bindings for those structs as well. Right now I am not able to get it correctly. Let's say I have a struct MyStruct for which I…
I'm writing my first Rust-based Python module, and it kills the Python process on import. I've got it down to a pretty minimal example, based loosely on the html-py-ever example (which does run for me without crashing).
I'm running Python 3.8 on an…
I'm working with some code that need to execute python method in Rust with Pyo3, but I have some problem in sahring a Struct between rust and python.
pub struct Wallet {
pub cash: i64
}
impl Wallet {
pub fn get_money(&mut self, num: i64) {
…
I want to wrap a function that takes an one-dimensional NDArray (rust-numpy) and an usize as parameters, and returns a one-dimensional array using PyO3 to call the code from python. Unfortunately, I can't find a good example of how to deal with the…
I've created a Rust library to use from Python to do some heavy processing. It works fairly well but I'm left with code that feels bloated and hard to maintain, so I figure there must be a better way. I've tried a few different options using a…
I have the following function that uses PyO3 to call a python function and get a result (in this case, an int that gets assigned to a i32):
fn run_python<'a, T: FromPyObject<'a> + Clone>(func_name: &str) -> Result {
Python::with_gil(|py|…