Tool to package Python applications as WebAssembly components
Project description
componentize-py
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
. See the
examples and
test directories
for examples.
For an example of running a sandboxed Python guest within a Python host, see component-sandbox-demo.
Installing from PyPI
pip install componentize-py
Building from source
For the time being, we use a temporary fork of WASI-SDK which enables both shared library support and dlopen/dlsym. Once those features are upstreamed, we'll switch. Specifically, the remaining patches are:
- https://github.com/WebAssembly/wasi-libc/pull/429
- https://github.com/WebAssembly/wasi-sdk/pull/338
- Additional, yet-to-be created PRs to enable dlopen/dlsym
Prerequisites
- Tools needed to build CPython (Make, Clang, etc.)
- Rust stable 1.71 or later and nightly 2023-07-27 or later, including the
wasm32-wasi
andwasm32-unknown-unknown
targets- Note that we currently use the
-Z build-std
Cargo option to build thecomponentize-py
runtime with position-independent code (which is not the default forwasm32-wasi
) and this requires using a recent nightly build of Rust.
- Note that we currently use the
For Rust, something like this should work once you have rustup
:
rustup update
rustup install nightly
rustup component add rust-src --toolchain nightly
rustup target add wasm32-wasi wasm32-unknown-unknown
Building and Running
First, make sure you've got all the submodules cloned.
git submodule update --init --recursive
Next, install WASI SDK to /opt/wasi-sdk
(alternatively, you can specify an
alternative location and reference it later using the WASI_SDK_PATH
environment variable). Replace linux
with macos
or mingw
(Windows) below
depending on your OS.
curl -LO https://github.com/dicej/wasi-sdk/releases/download/shared-library-alpha-2/wasi-sdk-20.16g86c5c116b0a6-linux.tar.gz
tar xf wasi-sdk-20.16g86c5c116b0a6-linux.tar.gz
sudo mv wasi-sdk-20.16g86c5c116b0a6 /opt/wasi-sdk
export WASI_SDK_PATH=/opt/wasi-sdk
Finally, build and run componentize-py
.
cargo run --release -- --help
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.4.2-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 61b759b706d75e05ac80363ac9e2f6d1d572540f97465edf0c8d2eb839a7a06b |
|
MD5 | 9034fc1985eaa2a0f25702fea679beac |
|
BLAKE2b-256 | 7b55dfe1e2c62a9af2da29f60f6012aecf876f05f1ad145cb2ff0c1bf1f97a3b |
Hashes for componentize_py-0.4.2-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6a352a58d48d6a39fa0012f0f2ca742ebd85b8451ca83f93c7a5c6f9c52dfbea |
|
MD5 | f997ebb7a2b41c6a7bc1efc99afecf96 |
|
BLAKE2b-256 | ca81fecaee2731b4c300ebeaa978686119fbc041e1d916a4d04a717f7fd82353 |
Hashes for componentize_py-0.4.2-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d51af29539f9ac4269ee393aabb7cf1113da01be735519cc2da695dfa396b3f7 |
|
MD5 | 46ef783f2fcc241cf754157749b2345f |
|
BLAKE2b-256 | 3b7f6119de31c6a95cd31daf54abdc91e1f32c6b316f420d4fc9268cbd2f07a7 |
Hashes for componentize_py-0.4.2-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b21623b711a69d5518e99cea421df4602da41c7ab8754b71c90bf41ea4349cbc |
|
MD5 | 84c55d2c933a4ed98eefcaeac46e339f |
|
BLAKE2b-256 | d6742b9eccfb011282eb2db0af65f0035b766979fa633f1c0984a0327b9316d3 |
Hashes for componentize_py-0.4.2-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88443cca626b752e16ac1d9f64aa6f39740dd56db12ca563385be6e879e17bbe |
|
MD5 | b8f875cc8cf24e9ce30be177f3ba980c |
|
BLAKE2b-256 | d5ca364ef9043c41ad5b6f44f1f3ce494dde234ed410020461b46981360cac66 |