Stream: general

Topic: How can a function exported by one WASM component be called?


view this post on Zulip Hua (Nov 28 2025 at 09:47):

I’m relatively new to WebAssembly and would appreciate some guidance on the following challenge.

I currently have the following setup:

My questions are:

I’ve looked through relevant documentation, but most resources focus on Guest/Host interoperability. I haven’t been able to find clear guidance on interoperability between two WASM components.

My use case seems similar to the one shown in this example:

https://github.com/bytecodealliance/wac/tree/main/examples

However, I’m interested in understanding how the underlying code that generates these WASM components actually works.

It would be beneficial if there were any similar project examples available.

Thank you!

WebAssembly Composition (WAC) tooling. Contribute to bytecodealliance/wac development by creating an account on GitHub.

view this post on Zulip Milan (rajsite) (Nov 28 2025 at 13:33):

The component model book goes through the concepts with a Rust component (calculator) calling a JavaScript component (adder): https://component-model.bytecodealliance.org/importing-and-reusing-components.html

The key bit is that the wit used to define the API of B is what A uses to generate Python bindings. The componentize-py docs show what it's like to generate bindings for a hello world wit: https://github.com/bytecodealliance/componentize-py?tab=readme-ov-file#getting-started
That example is exporting the interface, but in your version from the Python component it sounds like you'll want to import the interface.

Tool for targetting the WebAssembly Component Model using Python - bytecodealliance/componentize-py

view this post on Zulip Hua (Dec 03 2025 at 14:07):

Milan (rajsite)

The component model book goes through the concepts with a Rust component (calculator) calling a JavaScript component (adder): https://component-model.bytecodealliance.org/importing-and-reusing-components.html

The key bit is that the wit used to define the API of B is what A uses to generate Python bindings. The componentize-py docs show what it's like to generate bindings for a hello world wit: https://github.com/bytecodealliance/componentize-py?tab=readme-ov-file#getting-started
That example is exporting the interface, but in your version from the Python component it sounds like you'll want to import the interface.

Thank you for your reply.

I've reviewed the Rust component (calculator) example in the documentation. My needs are similar, but I require a Python version. I have searched extensively but have been unable to locate one. The available componentize-py examples focus on exporting components, whereas I specifically need the interface for importing a component into Python.

view this post on Zulip Joel Dice (Dec 03 2025 at 15:46):

Here's a quick example of building two components using componentize-py, composing them, and running the result:

mkdir compose
cd compose
python3 -m venv .venv
source .venv/bin/activate
pip install componentize-py
cat >worlds.wit <<EOF
package test:test;

interface foo {
  bar: func() -> string;
}

world thing1 {
  export foo;
}

world thing2 {
  import foo;
  export run: func() -> string;
}
EOF
cat >mything1.py <<EOF
from wit_world import exports

class Foo(exports.Foo):
    def bar(self) -> string:
        return "Hello, world!"
EOF
cat >mything2.py <<EOF
import wit_world
from wit_world.imports import foo

class WitWorld(wit_world.WitWorld):
    def run(self) -> string:
        return foo.bar()
EOF
componentize-py -d worlds.wit -w thing1 componentize mything1 -o thing1.wasm
componentize-py -d worlds.wit -w thing2 componentize mything2 -o thing2.wasm
wasm-tools compose -d thing1.wasm thing2.wasm -o composed.wasm
wasmtime run --invoke 'run()' composed.wasm

Last updated: Dec 06 2025 at 05:03 UTC