Skip to main content

Python SDK for Spin

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.23.0 spin-sdk==4.0.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:up/http-trigger@4.0.0 componentize app -o app.wasm"
EOF
cat >app.py <<EOF
from spin_sdk import http
from spin_sdk.http import Request, Response

class HttpHandler(http.Handler):
    async 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-4.0.0.tar.gz (238.5 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-4.0.0-py3-none-any.whl (483.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spin_sdk-4.0.0.tar.gz
  • Upload date:
  • Size: 238.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spin_sdk-4.0.0.tar.gz
Algorithm Hash digest
SHA256 0e7077417d4951dbc170ba44c5e89fb3c829b6cb239fc712cf64f39687589756
MD5 2fb4db1eb4d963806e8a1becedb6a810
BLAKE2b-256 d241eb9f9f4243a363363c7b9d3db42646d474a46286b39444acb010f3275e16

See more details on using hashes here.

Provenance

The following attestation bundles were made for spin_sdk-4.0.0.tar.gz:

Publisher: release.yml on spinframework/spin-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: spin_sdk-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 483.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spin_sdk-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4a9e97f08eb07eeef1d5fdf45c7cecd744d97ee1c241a5891e8d1e26bf2d8780
MD5 58f6dcec2142dfed4acdb15cf59b59e4
BLAKE2b-256 5187caf30c3310d644ff32b27b0aa1b27ec6d4665e7d507e2c9489be3a15b079

See more details on using hashes here.

Provenance

The following attestation bundles were made for spin_sdk-4.0.0-py3-none-any.whl:

Publisher: release.yml on spinframework/spin-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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