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.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c7676707a8ab2b2340ea39aa6d2d20466bac5dc7eb1e8eec062e1a6ddf5576d |
|
MD5 | 20fb13e97f2592db2741c1e69d22018a |
|
BLAKE2b-256 | ec4b0021e186dd41625b42f7be873a60d800e5f22c2f2d7d65f1cc74a0a6711a |
Hashes for componentize_py-0.4.1-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9cf6adff28dc1eeb5c6e7afbec3429af912fa8cf73d9fbbd659b18e782341b |
|
MD5 | 9befbbad88c9e32c271af7c524e3a29c |
|
BLAKE2b-256 | 2ec6efc9e02720f0299f554613fe0a6e1a1dc792be1095833a147b14f8bb74a9 |
Hashes for componentize_py-0.4.1-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01ed93e5b4ebe74c8bb0d904a7cdc5f9cc501d8e2e1bbfc2eb8a21cfe3d30274 |
|
MD5 | c2b928e77f2e141a320073744f667a74 |
|
BLAKE2b-256 | 06ff9f4f7e0b159b7fdce5da7d4bd2fb8939ec48f3a8509bddf6dbc0501bbe38 |
Hashes for componentize_py-0.4.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13379ff10501d80f61882c08d0c6e34bed9f483228d720d32ab187f6166eef2c |
|
MD5 | f49ca9c7760dac0221c07483fc62c15f |
|
BLAKE2b-256 | b4c7618c8e6babffc0fa6ee5a7051d3f4a672c8f053c1a63f7a140b1d621d3af |
Hashes for componentize_py-0.4.1-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c3e961295131cd4460da221be682b262ef2729cb55bd0be690b03214bf74ffe |
|
MD5 | 26f5ea237d128351955f38efda526977 |
|
BLAKE2b-256 | 2f3029f989f598df3b4b8dab7a5ed273fc9af48941d0eb3182d965fdbcfc1768 |