Skip to main content

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:

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 and wasm32-unknown-unknown targets
    • Note that we currently use the -Z build-std Cargo option to build the componentize-py runtime with position-independent code (which is not the default for wasm32-wasi) and this requires using a recent nightly build of Rust.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

componentize_py-0.3.2.tar.gz (2.6 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

componentize_py-0.3.2-cp37-abi3-win_amd64.whl (31.6 MB view details)

Uploaded CPython 3.7+Windows x86-64

componentize_py-0.3.2-cp37-abi3-manylinux_2_28_x86_64.whl (34.6 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ x86-64

componentize_py-0.3.2-cp37-abi3-manylinux_2_28_aarch64.whl (34.4 MB view details)

Uploaded CPython 3.7+manylinux: glibc 2.28+ ARM64

componentize_py-0.3.2-cp37-abi3-macosx_11_0_arm64.whl (23.7 MB view details)

Uploaded CPython 3.7+macOS 11.0+ ARM64

componentize_py-0.3.2-cp37-abi3-macosx_10_7_x86_64.whl (24.1 MB view details)

Uploaded CPython 3.7+macOS 10.7+ x86-64

File details

Details for the file componentize_py-0.3.2.tar.gz.

File metadata

  • Download URL: componentize_py-0.3.2.tar.gz
  • Upload date:
  • Size: 2.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.0rc1

File hashes

Hashes for componentize_py-0.3.2.tar.gz
Algorithm Hash digest
SHA256 f7181e2747e7be0dacc4b08a38036b28bf8f182aef974df430f8f0079d15c3d7
MD5 8dca2b14c99976c8b84e10c945a1c85f
BLAKE2b-256 4cb884713a79ef82206ecca30546ca2bf457d92d5d1ed4fa0b46cc32d7acf3c3

See more details on using hashes here.

File details

Details for the file componentize_py-0.3.2-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for componentize_py-0.3.2-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 49741b0f305310c986b934da2228550c7b021abdce0d5473c27f7e0978a1092a
MD5 df29af1a3873c1c8b0891b2ed8bc2764
BLAKE2b-256 5fb68d65fbc32a7e85005d4d130e02f5a602e018e6ebc42d0708ee1e54d78b1d

See more details on using hashes here.

File details

Details for the file componentize_py-0.3.2-cp37-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for componentize_py-0.3.2-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0169962c3646f571e62f2b695924329a7dcc7543f008b78c47fa2868f0218a2e
MD5 a56ef4a7165c7b48360bb4319d34edb0
BLAKE2b-256 8a2b0e8fd109df639f00d588835f32052601371c100862f72fff6a415187ab81

See more details on using hashes here.

File details

Details for the file componentize_py-0.3.2-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for componentize_py-0.3.2-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 689b8676806fe88fe2b6e8dfbab37ef4c455ceef99d2759a429f84b69a381097
MD5 da80fd8bfd6346ed5c73a7429c01bc29
BLAKE2b-256 af34451c8026cb1671500cce64130393d02ccee31b6f2174bedd936ac21ff51d

See more details on using hashes here.

File details

Details for the file componentize_py-0.3.2-cp37-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for componentize_py-0.3.2-cp37-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b79f56cf6ddd46b280faaf001cdf7fdbf19e2cbb2b00399ff3b7ddf01182ce5
MD5 011c83a0a68efcd725e700f15cd3bbf4
BLAKE2b-256 8b8ef877189a48770366c2f05ce06e9b65e0e25d11403336c0dd7c7e855a3975

See more details on using hashes here.

File details

Details for the file componentize_py-0.3.2-cp37-abi3-macosx_10_7_x86_64.whl.

File metadata

File hashes

Hashes for componentize_py-0.3.2-cp37-abi3-macosx_10_7_x86_64.whl
Algorithm Hash digest
SHA256 0097e561be9427de999ab9b67d238b653b36ea1beff74471e180ddb276b9f4e5
MD5 6350ab95078dfb5344efb46287028264
BLAKE2b-256 d30a8b5d592fc8e4a3f470ae459cc21308aa26e66c21ddd733489f4c835d1f19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page