Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: python bindings #247

Open
truenicoco opened this issue Mar 28, 2024 · 5 comments
Open

Feature request: python bindings #247

truenicoco opened this issue Mar 28, 2024 · 5 comments

Comments

@truenicoco
Copy link

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

@gferon
Copy link
Collaborator

gferon commented Apr 6, 2024

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 😂

@truenicoco
Copy link
Author

truenicoco commented Apr 6, 2024 via email

@WhyNotHugo
Copy link

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.

@ThUnD3r-Gr33n
Copy link

does this mean there is work in progress ?

@WhyNotHugo
Copy link

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-async to 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants