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

Dynamically opened python library #2668

Open
pingiun opened this issue Oct 9, 2022 · 1 comment
Open

Dynamically opened python library #2668

pingiun opened this issue Oct 9, 2022 · 1 comment

Comments

@pingiun
Copy link

pingiun commented Oct 9, 2022

I want to optionally allow python plugins for my project. It would be nice if PyO3 could be configured such that python isn't linked at compile time and instead the .so is loaded dynamically at runtime and symbols are also loaded dynamically.

An alternative would be to statically link python to my project so that it's always available but that would drastically increase my binary size.

I believe this can be implemented using the libloading crate, maybe macros can be used in some way to convert the extern "C" blocks into dynamic symbol lookups? I'm not too familiar with macros, so I cannot say for sure.

@davidhewitt
Copy link
Member

davidhewitt commented Oct 13, 2022

So I think this would require a complete alternative implementation of the pyo3-ffi crate which is able to lazily load the symbols it needed. I'm not against having this, however it's too niche a use-case for me to do this. It could be a feature, I think it'd be a lot of work though tbh.

An alternative could be to build your own .so which implements the Python plugin engine (and uses PyO3's existing link model), and then your binary could dynamically load that .so if a Python plugin is requested.

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

No branches or pull requests

2 participants