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.68 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.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ab8f1892cd02b85f89b178f4e7822d550814859b98ae73eabaf9e031e5acf0a |
|
MD5 | 2f453264dbed3d65ce8a84ca1caae6a1 |
|
BLAKE2b-256 | 5b39d0718303c4955cff081da5c80d5a35e458fa087acdf1c7540f646e036408 |
Hashes for componentize_py-0.4.0-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 124011d3fd34e3c3fc3a629f7544ae7ac6bac90a73b4b5c9cb8796fb71a11bcd |
|
MD5 | 4893c3adefef3113fc0dcd70920799d5 |
|
BLAKE2b-256 | 818c3e3b5492011c3fcc5f417af2c5b65c94e2006470ee2286b9f77f759bb440 |
Hashes for componentize_py-0.4.0-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | afed0e23fca18eee9509c8a593994893287f8b63a30b1e79cdf3b259750c319d |
|
MD5 | 725dc787826ecd40537a8f8a2fe0f354 |
|
BLAKE2b-256 | 5428df6b07d6fe211fb1f2172c52824d23114a5f06fa0f977af99447b0dbb010 |
Hashes for componentize_py-0.4.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f725ffb8df6184bdb8c923704c7923ad36c87c154d3f62b7f4460bc492086f43 |
|
MD5 | 3bccfe10fdfad6309de9cecc9d93df87 |
|
BLAKE2b-256 | b9df7cb286554b517278bb231001ef7737bccb9aee67ac6970af4d0650c6655b |
Hashes for componentize_py-0.4.0-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b52ed9e81e8dbcbf76e2c10df8c017f3553dbebc2e948b947a9f6f2b267120e |
|
MD5 | 01d92231bf50c6b21322350b9730fff7 |
|
BLAKE2b-256 | 066c8a1e04908e2bb6c35d1b32aaf6278bf6b4d30f550332e6f02d5b3a87583b |