Acces rust type through python ffi

I have a very simple project that works like a transpiler, taking a kind of metalanguage and converting it into Rust code. (Yes, it's a bit like reinventing gRPC.)

Currently, I have a file with numerous types, like:

#[derive(FromWire, ToWire)]
pub struct Foo {
   pub a: String
}

FromWire and ToWire are traits that provide from_wire and to_wire methods.

The idea is to expose these types to Python without implementing code generation for Python. This choice is both for performance reasons in encoding and decoding and, admittedly, because I want to avoid extra coding work.

I haven't worked extensively with FFI bindings before, so I'm looking for advice on the best approach to create a Python package that can be deployed to PyPI.

I'm particularly interested in opinions because these files contain just types, like the ones shown earlier, performing similar functions. I'm hoping there’s existing automation for generating bindings.

Never had the chance to work with it, but maturin looks nice and powerful.

1 Like

Yes, trying it out and looks like amazing, thanks!

1 Like