Experimental SDK for Spin and Componentize-Py
Project description
Experimental Spin SDK for componentize-py
This is an experimental SDK for creating Spin apps using componentize-py
.
API Documentation
Example
Prerequisites
- Python 3.10 or later and pip
- componentize-py
- spin-sdk
- MyPy
- This is optional, but useful for during development.
- Spin 2.2 or later.
- As of this writing Spin 2.2 has not yet been released, so we must use a temporary fork which supports the
0.2.0-rc-2023-12-05
snapshot of WASI. You can find pre-built binaries here.
- As of this writing Spin 2.2 has not yet been released, so we must use a temporary fork which supports the
Once you have Python and pip installed, you can use the latter to create and enter a virtual environment and then install the desired packages
python -m venv .venv
source .venv/bin/activate
pip install componentize-py==0.9.2 spin-sdk==0.0.4 mypy==1.8.0
Hello, World
A minimal app requires two files: a spin.toml
and a Python script, which we'll name app.py
:
cat >spin.toml <<EOF
spin_manifest_version = 2
[application]
name = "hello"
version = "0.1.0"
authors = ["Dev Eloper <dev@example.com>"]
[[trigger.http]]
route = "/..."
component = "hello"
[component.hello]
source = "app.wasm"
[component.hello.build]
command = "componentize-py -w spin-http componentize app -o app.wasm"
EOF
cat >app.py <<EOF
from spin_sdk.http import simple
from spin_sdk.http.simple import Request, Response
class IncomingHandler(simple.IncomingHandler):
def handle_request(self, request: Request) -> Response:
return Response(
200,
{"content-type": "text/plain"},
bytes("Hello from Python!", "utf-8")
)
EOF
Once you've created those files, you can check, build, and run your app:
mypy app.py
spin build -u
Finally, you can test your app using e.g. curl
in another terminal:
curl -i http://127.0.0.1:3000
If all goes well, you should see:
HTTP/1.1 200 OK
content-type: text/plain
transfer-encoding: chunked
date: Tue, 09 Jan 2024 18:26:52 GMT
Hello from Python!
Please file an issue if you have any trouble.
See the examples directory in the repository for more examples.
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 Distribution
File details
Details for the file spin-sdk-0.0.4.tar.gz
.
File metadata
- Download URL: spin-sdk-0.0.4.tar.gz
- Upload date:
- Size: 65.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e85507845ce1257a76188b944b0550a926c806ee1858ff65af779f6f91742540 |
|
MD5 | 68dea0176af560e51752a918a25ee70f |
|
BLAKE2b-256 | 0fc5cd76f698665f5d3e60b22137c30b97fd8a346697f0a8fd49411c7680637e |
Provenance
File details
Details for the file spin_sdk-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: spin_sdk-0.0.4-py3-none-any.whl
- Upload date:
- Size: 88.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 15e170c68169e2aa3ba4b72db2497bf31bd4baa46c9ad6c8c038b3067ca1e4ab |
|
MD5 | f3fefad0bf36b8e8af649edf9a1e444d |
|
BLAKE2b-256 | 0373e6b1522d689fed18e30bdc7e7e303f880a79d2d232cd12bb6bb29d74b3b2 |