Feature request: python bindings
This lib looks great and I'd be thrilled to use it to replace signald in my XMPP/signal bridge.
Would you consider adding some (possibly autogenerated) python bindings? Looks like pyo3-asyncio would make that possible. I'd do it but I'd have to learn rust first. xD
I could give it a try but I'm really not sure how this would turn out. I suppose it would be relatively easy to expose some functions and types of the public API, but I'm mostly worried about having to deal with pip 😂
Oh, it’s super cool if you have a look! For dealing with pip, it’s not that bad, the hard part is actually that there’s too much choice and it’s overwhelming to pick a tool amongst the different ones with overlapping functionality. I usually use poetry, but if the idea is just to upload to PYPI then I think twine does just that. There’s also hatch, which looks promising… Yeah I know this is not helpful, sorry. xD
I like poetry: https://python-poetry.org/
A contributor of slidge made a rust-based text parser https://github.com/BluebonnetField/slidge-style-parser to be called from python and they used Maturin apparently, so maybe that’s better. https://www.maturin.rs/
Thanks for considering it. :)
Le 6 avr. 2024 à 14:58, Gabriel Féron @.***> a écrit :
I could give it a try but I'm really not sure how this would turn out. I suppose it would be relatively easy to expose some functions and types of the public API, but I'm mostly worried about having to deal with pip 😂 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>
I recommend using maturing for this: https://www.maturin.rs/
We basically need to write the Rust functions that you want to expose and annotate them with #[pyfunction]. Maturin does the work of generating bindings and building the Python module itself (you don't need poetry, etc).
You can't expose generic types, so types like presage::manager::Manager cannot be exposed directly; we'd need to expose presage::manager::Manager<presage_store_sled::SledStore, Linking> as one type, and presage::manager::Manager<presage_store_sled::SledStore, Registered> as another, etc.
Internally, maturing uses pyo3. Types to be exposed must be explicitly declared. Ideally, we'd work with opaque types and only include the necessary getters. See also: https://pyo3.rs/v0.22.5/rust-from-python
Given these constraints, we should include a new library called presage-py, which has a dependency on presage, presage_store_sled and pyo3.
does this mean there is work in progress ?
Not on my part; I have several deadlines upcoming and don't have any spare bandwidth to focus on it.
Some further comments from IRC in case somebody wants to pick this up:
- We can use
pyo3-asyncto bridge Rust async with Python async. This fits well into the maturin ecosystem. - We likely want to pass callbacks for events from the Python side to Rust.
- We should expose a single async function so that Python can start task which listens for events from the Signal server.