Install python modules - componentize-py, wasmtime-py and Runtime - wasmtime
- Create the WIT world you'd like. Below is simple
hello.witthat would print some string whenhellofunction is called
package example:hello;
world hello {
export hello: func() -> string;
}- To understand the internal bindings, you can always run below and create the GUEST; (Optional)
componentize-py -d hello.wit -w hello bindings hello_guest
- Create the module in python and save it with name of the
app.py(ACTUAL APP)
import hello
class Hello(hello.Hello):
def hello(self) -> str:
return "Hello, World!"- Generate the component
app.wasmwith below command fromhello.witand the module that was created aboveapp.py
componentize-py -d hello.wit -w hello componentize --stub-wasi app -o app.wasm
or
componentize-py -d hello.wit -w hello componentize app -o app.wasm
- Create the host-side bindings for the component
app.wasm
python3 -m wasmtime.bindgen app.wasm --out-dir hello_host
- Now, we can write a simple host app using those bindings:
from hello_host import Root
from wasmtime import Config, Engine, Store
config = Config()
config.cache = True
engine = Engine(config)
store = Store(engine)
hello = Root(store)
print(f"component says: {hello.hello(store)}")