Skip to main content

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

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.16.0 spin-sdk==3.3.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


Download files

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

Source Distribution

spin_sdk-3.4.0.tar.gz (81.3 kB view details)

Uploaded Source

Built Distribution

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

spin_sdk-3.4.0-py3-none-any.whl (117.3 kB view details)

Uploaded Python 3

File details

Details for the file spin_sdk-3.4.0.tar.gz.

File metadata

  • Download URL: spin_sdk-3.4.0.tar.gz
  • Upload date:
  • Size: 81.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for spin_sdk-3.4.0.tar.gz
Algorithm Hash digest
SHA256 2ba6652bf219a6da1f7b33e4205a36082463b9b9ae39f91234dee92e136179d4
MD5 d5bf2e0d0ea142c11c5499d8fa5c9d03
BLAKE2b-256 f52780a23a70bedba26d152d5256b8ffa1aaca5ad7e5b8a5dae20024e65b952b

See more details on using hashes here.

File details

Details for the file spin_sdk-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: spin_sdk-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 117.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for spin_sdk-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ccff6abcd4d582d58350167f3aac34c592b8e2a51bb368daa8d2ac4387ada71a
MD5 bc24719245ea0fb8de9e3c4cf62f2490
BLAKE2b-256 eec3dcb35ff545d8da1458c31d78df73ef16ac55d9404174da10a99b4beae46f

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