Tool to package Python applications as WebAssembly components
Project description
componentize-py
A Bytecode Alliance project
This is a tool to convert a Python application to a WebAssembly component. It takes the following as input:
- a WIT file or directory
- the name of a WIT world defined in the above file or directory
- the name of a Python module which targets said world
- a list of directories in which to find the Python module and its dependencies
The output is a component which may be run using
e.g. wasmtime
.
Getting Started
First, install Python 3.10 or later and
pip if you don't already have them. Then,
install componentize-py
:
pip install componentize-py
Next, create or download the WIT world you'd like to target, e.g.:
cat >hello.wit <<EOF
package example:hello;
world hello {
export hello: func() -> string;
}
EOF
If you're using an IDE or just want to examine the bindings produced for the WIT
world, you can generate them using the bindings
subcommand:
componentize-py -d hello.wit -w hello bindings .
Then, use the hello
module produced by the command above to write your app:
cat >app.py <<EOF
import hello
class Hello(hello.Hello):
def hello(self) -> str:
return "Hello, World!"
EOF
And finally generate the component:
componentize-py -d hello.wit -w hello componentize app -o app.wasm
See the examples directories for more examples, including various ways to run the components you've created.
Known Limitations
Currently, the application can only import dependencies during build time, which
means any imports used at runtime must be resolved at the top level of the
application module. For example, if x
is a module with a submodule named y
the following may not work:
import x
class Hello(hello.Hello):
def hello(self) -> str:
return x.y.foo()
That's because importing x
does not necessarily resolve y
. This can be
addressed by modifying the code to import y
at the top level of the file:
from x import y
class Hello(hello.Hello):
def hello(self) -> str:
return y.foo()
This limitation is being tracked as issue #23.
See the issue tracker for other known issues.
Contributing
See CONTRIBUTING.md for details on how to contribute to the project and build it from source.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for componentize_py-0.11.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae1e6bd7655111e56a91dbe2d40a5827bf95280ed5a78128447c72bcd1fea3b2 |
|
MD5 | b6886ffdf21a22a979d100e7b509d6be |
|
BLAKE2b-256 | 6044abc95c9a442f1424b35486b1b5e8c9f2d05f73d5ff94ea9ce817124ce561 |
Hashes for componentize_py-0.11.1-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d807d5cb809518ac2e1a3550f05f5c0f2323b264a7f4caca2f48e90bec51d9c3 |
|
MD5 | 234e4195ac10b51ad7c7ce97f75e86e3 |
|
BLAKE2b-256 | d8798723219ce64a99ed4321f352be97464361374970e166e6fc02f02fa52684 |
Hashes for componentize_py-0.11.1-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20eacde30e1793408839d8d32144b9363139cf16254de309cdf08a9839241dd8 |
|
MD5 | 9c07bd1489cd88c979f54d940068356c |
|
BLAKE2b-256 | 7b7c8cfdf0d4690b591488fa6d1e721870d1b94009996c2a0b8c9e1a440aaed6 |
Hashes for componentize_py-0.11.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f219b62d409be4b23d700f7c91f36b7cd70522c162d6f1bdbdafcf8e8da2567a |
|
MD5 | 59a3bce8bd2edb9ebd2d92759fbbceab |
|
BLAKE2b-256 | 624e3c86c750559559d946940c07ede89d26f9436e8964ad48c127b3f7dd30e5 |
Hashes for componentize_py-0.11.1-cp37-abi3-macosx_10_12_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a49122b0ee9ca255ada90b8077832164be165e26851207b2622efc911b75908 |
|
MD5 | 4501fd7e0c7fba8a654b7bc53be2c94c |
|
BLAKE2b-256 | 5a195278b39a942d29f0cd82ef8ceaa31e3a298b88ff72411c5e90ccc7605d42 |