This is an experiment to build a Spin Python SDK using CPython, Wizer, and PyO3.
Use the following command to install the py2wasm plugin and then build the example Spin app:
spin plugins update
spin plugins install py2wasmIf you'd like to try out the latest features, you can use the following command to install the unstable canary version of the plugin:
spin plugins install --url https://github.com/fermyon/spin-python-sdk/releases/download/canary/py2wasm.jsonAfter installing the plugin, you can run the examples found in this repo.
Note: These examples track Spin's main branch, so you may need to ensure you are using the canary Spin release. See https://developer.fermyon.com/spin/install.
cd examples/hello world
spin build
spin upNote: When using the devcontainer for development, the following dependencies are already installed for you. To prevent speed up build times and prevent compatibility issues, a pre-compiled artifact of cpython for wasi is used rather than compiling from source. (https://github.com/brettcannon/cpython-wasi-build/releases/tag/v3.11.4)
- WASI SDK v16 or later, installed in /opt/wasi-sdk
- CPython build prereqs (e.g. Make, Clang, etc.)
- Rust (including
wasm32-wasitarget) - Spin
- pipenv for installing Python project dependencies
First, perform a git submodule update to update the cpython submodule. (Unnecessary if using devcontainer)
git submodule update --init --recursiveThen, build CPython for wasm32-wasi. (Unnecessary if using devcontainer)
./build-python.shThen, build the spin-python-cli: (Unnecessary if using devcontainer)
makeFinally, build and run the example app:
cd examples/hello_world
$CARGO_TARGET_DIR/release/spin-python app -o app.wasm
spin up*Note: spin-python and py2wasm are just different names for the same command. spin-python is used in the context of running the binary in a standalone context while py2wasm is used when the command is run via Spin. In the samples provided in the examples directory, the spin build command depends on the plugin py2wasm being installed. Therefore, to test the locally built spin-python binary, replace the build command in the spin.toml to invoke it using spin build.
[component.build]
command = "$CARGO_TARGET_DIR/release/spin-python app -o app.wasm"