Experimental SDK for Spin and Componentize-Py
Project description
Spin Python SDK
This is an SDK for creating Spin apps using Python.
Note that this SDK supersedes an earlier, experimental version, which may be found in the old-sdk branch.
API Documentation
Example
Prerequisites
- Python 3.10 or later and pip
- componentize-py
- spin-sdk
- Spin 2.2 or later.
- MyPy -- This is optional, but useful for during development.
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.13.3 spin-sdk==3.2.1 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 import http
from spin_sdk.http import Request, Response
class IncomingHandler(http.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:
python -m 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 something like:
HTTP/1.1 200 OK
content-type: text/plain
content-length: 18
date: Thu, 11 Apr 2024 17:42:31 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-3.2.1.tar.gz
.
File metadata
- Download URL: spin_sdk-3.2.1.tar.gz
- Upload date:
- Size: 68.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ca44466fc2db7ffe4b53c1e7675da2b5cece32c886cceffb3924c0ed71a95d4 |
|
MD5 | 83cd9517c32e15a2be0011e9bbedcaa4 |
|
BLAKE2b-256 | 826a92df25e64e2fb09811d75a7d1a4a798131636420668cdb89f137e88d374c |
File details
Details for the file spin_sdk-3.2.1-py3-none-any.whl
.
File metadata
- Download URL: spin_sdk-3.2.1-py3-none-any.whl
- Upload date:
- Size: 94.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffbd581aa4550b328f78f5541aa02f65df2434177e4b66aa98237745fd06a739 |
|
MD5 | 77d0cab69b59ec4de70f633e5155890a |
|
BLAKE2b-256 | 581558f7e29ed88c21e7f2c946d3899e443c6f8c14c2aee07c7dfbe52d4cead4 |