Skip to content

spinframework/spin-python-sdk

Repository files navigation

spin-python-sdk

This is an experiment to build a Spin Python SDK using CPython, Wizer, and PyO3.

Installing the Plugin

Use the following command to install the py2wasm plugin and then build the example Spin app:

spin plugins update
spin plugins install py2wasm

If 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.json

Running Examples

After installing the plugin, you can run the examples found in this repo:

cd examples/hello world
spin build
spin up

Building and Running

Prerequisites

  • WASI SDK v16 or later, installed in /opt/wasi-sdk
  • CPython build prereqs (e.g. Make, Clang, etc.)
  • Rust (including wasm32-wasi target)
  • Spin
  • pipenv for installing Python project dependencies

Instructions

First, build CPython for wasm32-wasi.

./build-python.sh

Then, build the spin-python-cli:

make

Finally, 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"