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
tests 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-1/wasi-sdk-20.15ge8bb8fade354-linux.tar.gz
tar xf wasi-sdk-20.15ge8bb8fade354-linux.tar.gz
sudo mv wasi-sdk-20.15ge8bb8fade354 /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.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fb2124fe7b96dba4339935fb1e0c16a8f9181eb368d6d312a105fb8a6833887 |
|
MD5 | 117705eb52dcf08bcf81237b3a13152b |
|
BLAKE2b-256 | 8ab158e311f5e07f982f6208f0e2d89e00db794685a387c17c72c84e73835430 |
Hashes for componentize_py-0.3.0-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2e34d6250723bbf30f7d2b8af1628ebe752a3eb0d4a1420d384a90b69b04c5e |
|
MD5 | 24d7bc40b3a335d734649cac9efdf729 |
|
BLAKE2b-256 | 8fa6a0d1259632483b01ff62f063cfaa7e851e9023ac269019f579f5a921c58d |
Hashes for componentize_py-0.3.0-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c31c7f7bcc801bdd0d2dec5434b2edc783e3b08c74f3484b365b536b38a1cfb |
|
MD5 | 21cc1ac7e1ff7620de76402d1b5f236d |
|
BLAKE2b-256 | aff61f34aa2b78df32741fb5f95720a57bce2793e6dceb730a5116663420febf |
Hashes for componentize_py-0.3.0-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 480b7dbbdb62f323bbf6a2fadf7a1ac35e45d171e3460c7fce8bb44ceb08515f |
|
MD5 | fa3fe66004930d560387a8bf9859c9ea |
|
BLAKE2b-256 | 81a6fda57eeb97cedd9bf1a231b892aba5607dcecd1911ebae649b17a85f866e |
Hashes for componentize_py-0.3.0-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7183b8e8358a753a7fe98265fab5a7c042bae524cea336035a0e8d775e4eeb51 |
|
MD5 | 8644d5c27a8382f036b5b74b469d0a47 |
|
BLAKE2b-256 | 599bd469cd0dd2906db082aff556c7c46a6f285e7c4ebe17e71ffaba4cb03894 |