Comments (9)
It's definitely on our radar, and something we would like to make happen. Technically it's already possible to do. The issue is that CPython or another interpreter must be compiled to WASM, and then load python code and run it. So the complexity on both the implementation and well as the plug-in development experience is quite high.
We're still watching the Python community make progress here and are excited for it. If we ship something on the PDK side for Python too soon, it might require users to make really significant changes to their plug-ins.
from extism.
I have a Python use case, but not a deep Python knowledge. I understand that Python does sometimes do some compilation to a kind of bytecode? Is there a WASM target for Python instead of a WASM Python host?
from extism.
I have a Python use case, but not a deep Python knowledge. I understand that Python does sometimes do some compilation to a kind of bytecode? Is there a WASM target for Python instead of a WASM Python host?
The way this would work would be similar to the JS-PDK: https://github.com/extism/js-pdk
I'm actually debating making that thing universal for all dynamic language like this. But the steps are roughly:
- Compile the interpreter to Wasm (usually not too hard as most of them are written in C). This singlestore project would do the trick.
- Load the Wasm program and evaluate the language's standard library source code and and your application source code.
- Use Wizer to freeze the state of the post-initialized machine into a new Wasm file
- For each function your plugin exports, compile an equivalent thunk function in Wasm code and expose as a Wasm export. The thunk will essentially grab the VM context and invoke the exported function by name in python/js/whatever.
What comes out of this process is another Wasm file which can be used as an Extism plugin
from extism.
I've sometimes wondered if the best path for Python PDK support would be via something like Nuitka or another transpiler. That would avoid having to run the entire python interpreter and let the byte code be far smaller.
from extism.
@z4ce - that is an interesting approach! a quick glance through the project docs didn't show much in the form of direct compilation to wasm bytecode though - do you have a link that describes the approach?
If we can get to LLVM IR from Nukita, we could link the extism imports (https://github.com/extism/c-pdk/blob/main/extism-pdk.h#L9-L60), but if there's a custom backend generator, it would take a bit more work. Maybe there's a way to link this into the Python source though and Nukita can handle it?
from extism.
Nuitka definitely doesn't have a wasm target right now. I did spend a little bit more time looking at Nuikta and it looks like it relies heavily on libpython -- and I'm not sure how adaptable it might be to being statically linked into a wasm module. It would be interesting to try to compile a program with Nuitka into a statically linked binary with WASI as the target and see what it does.
Another thought could be something like https://github.com/py2many/py2many
It seems to try to convert python to several other languages and does so in more direct way -- but it only supports a subset of python. None of these types of projects seem to be trying to emulate the full standard library or anything.
from extism.
May we can use https://github.com/RustPython/RustPython to run the plugin?
from extism.
I've been doing a few experiments with making a Python PDK. I made some progress using rustpython but want to look at a few more options and commit to getting it done. I've been trying to post in the #python-pdk discord channel when i can if anyone wants to join there and help.
from extism.
I pushed up some code using RustPython https://github.com/extism/python-pdk
But I think we still need to strategize on a direction: extism/python-pdk#1
Would love community input or help here.
from extism.
Related Issues (20)
- feat: Add ability to dump memory to a file when an error occurs
- Rust SDK Example has an Error HOT 1
- Static linking extism with c and c++ sdks HOT 1
- Plugin Errors Propagating as segfault HOT 2
- Regression: Can't cancel multiple calls for the same plugin instance HOT 1
- Implement Java PDK HOT 1
- The runtime only returns a generic error when calling `extism_plugin_error` HOT 1
- Improve MSVC support HOT 5
- via proto conversation: refine extism error message when plugin calls fail
- via proto conversation: add example of using extism+tracing to rust runtime HOT 1
- Build linux libextism on manylinux/musllinux containers HOT 8
- Add extism_load_v128/extism_store_v128
- Double mutable borrow issue for `host_fn` with Rust SDK HOT 4
- Error when passing an empty String from Plugin to Runtime via a host function or a logging macro HOT 3
- Add building and installing cmake config mode package
- [Question] How to reload plugin with new wasm file? HOT 6
- extism_length returns garbage values when an ExtismPointer is not aligned with an alloc HOT 1
- feature: Give users a way to manage timeouts from inside host functions HOT 3
- [Question] nodejs call rust wasm function failed. HOT 2
- [Question] C plugin example build failed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from extism.