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-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.1-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4960eb090e3ece6b3cec0525afa1c3aca6aa069fa87cdb97d6fc94bfe429d3a3 |
|
MD5 | 2bb52a84f3cd9f2cceb4339fb671eeff |
|
BLAKE2b-256 | d8487a6f82427eb68613e4710de455c5d227502f64f0ad5becca4d0341c0e716 |
Hashes for componentize_py-0.3.1-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6a49291f1b994a89aee58a16003e86b05773a381ba0a1e60fb441194d94523d |
|
MD5 | fbd15c9ea3819c7ca2759f6a14a6c443 |
|
BLAKE2b-256 | a2ea2ec32cfde5b951477139fbef9189384b97e392f3e002a369c6efff2ef5ad |
Hashes for componentize_py-0.3.1-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f259372819dcd8d3c22a4067a9d1dd353c3139f8c2af5211ef1b52fc7b1524a9 |
|
MD5 | 7c008559a93c0c9c9f3cf9ce827cba16 |
|
BLAKE2b-256 | 81b4f5a6465ea6a14b5c979539fa0f032f341ead3817cf88158ccf5cdb5f24f0 |
Hashes for componentize_py-0.3.1-cp37-abi3-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 308812f35db2feaa07c18f37cff61b45439c6eaa452253e5aa32d19ef37446de |
|
MD5 | 655edbda29c92182455be5d36c3d1d06 |
|
BLAKE2b-256 | facf78bf15ef7eb38959c09a2101916d081d712aad88ceb39b12e883cd69a60b |
Hashes for componentize_py-0.3.1-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d30ca88beb9d9389b63b686d1c61de1624df4f863dbcda9de890ece94df5944f |
|
MD5 | b199867e14fa328492b66b93be5551da |
|
BLAKE2b-256 | 176b2bdcef3885bd8c76893a980a3e624336956914d05f94d43d63b56763d95f |