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.13.3 spin-sdk==3.1.0 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.2.0.tar.gz (68.8 kB view details)

Uploaded Source

Built Distribution

spin_sdk-3.2.0-py3-none-any.whl (94.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spin_sdk-3.2.0.tar.gz
  • Upload date:
  • Size: 68.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for spin_sdk-3.2.0.tar.gz
Algorithm Hash digest
SHA256 0e0fac35bdd1e8ab853e6b70c71bceec2ab0d3bbfe7baef4ad4cb05b6104fcc0
MD5 72d7afa0351c62c14bd2f11bad1e1d2e
BLAKE2b-256 3759ac9a8006d176c42a4bc7a3bc4442a38c0108145eabc68cf082e2a9b25202

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: spin_sdk-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 94.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.8

File hashes

Hashes for spin_sdk-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc24a95a7cab1453cf2c6f9d2168329ce59bd0d5e85033d6c2297c2e149de6af
MD5 a6fafdcdab57cc574e85d6939b1f0682
BLAKE2b-256 f6534411742c94628425210915fb29a1d99235e457abb53a54a498350bb17251

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page