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.3.3-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88387ae83a5a04d15fd23aa6a0ab822516d15023f8a0b12630a2c3ba054f1949 |
|
MD5 | 9be86dd7bd7bc644e8de8e29ac07bbfc |
|
BLAKE2b-256 | de1addd8a8b2f64e06e95952c715812952f59b3a99b29401041c61e52463bd18 |
Hashes for componentize_py-0.3.3-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02fa4f13fcd956d9072052639293542b74d5b5e4e0ea4997395634c16d6f85c2 |
|
MD5 | ab94d23330f97449581d051daf7b7bd0 |
|
BLAKE2b-256 | 084c5f6c5f383ec05ab8476fb6166624001e306fb13e2a57c077794b42147115 |
Hashes for componentize_py-0.3.3-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9641bb22cce0910a45576a978703e27afddcc9e3c295c5b43a0212badc5ec62 |
|
MD5 | 6d9acd73ceebc982575af26177a7ddce |
|
BLAKE2b-256 | b3afc14ad87401f18a25d7bcf6e4ed59efb5800447609710210ce44b7cf150b9 |
Hashes for componentize_py-0.3.3-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ec259b63bd8c89ebfce79f25629cb379ca4262f090fbf33798454a92ee85858 |
|
MD5 | 283c824fe210da3d37683dacb83237eb |
|
BLAKE2b-256 | 81f4a90be5928e823d20b7d2ae66773a6435cfacdde56c0971fcda1d24ea6bac |
Hashes for componentize_py-0.3.3-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b246b2ebb98bb9859611911ddf8d6049e2c75aa5540949d3b607ac2ff00c38e9 |
|
MD5 | 49f2f24b65c79af9a8658c0c9a534294 |
|
BLAKE2b-256 | 17f182a9ae15659989feb4764e7fb915b8b00bb51d760deb2c87449f8befa392 |