Skip to content

Commit 6f97b0a

Browse files
committed
docs(content/v4): further Python SDK/example amendments
Signed-off-by: Vaughn Dice <vdice@akamai.com>
1 parent ac9a62d commit 6f97b0a

11 files changed

Lines changed: 23 additions & 20 deletions

content/v4/http-outbound.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ HTTP functions and classes are available in the `http` module. The function name
184184
from spin_sdk import http
185185
from spin_sdk.http import Request, Response, send
186186

187-
class WasiHttpHandler030Rc20260315(http.Handler):
187+
class HttpHandler(http.Handler):
188188
async def handle_request(self, request: Request) -> Response:
189189
response = await send(Request("GET", "https://random-data-api.fermyon.app/animals/json", {}, None))
190190
return response

content/v4/http-trigger.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ addEventListener('fetch', async (event: FetchEvent) => {
228228

229229
> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-python-sdk/v4/)
230230
231-
In Python, the application must define a top-level class named `WasiHttpHandler030Rc20260315` which inherits from [http.Handler](https://spinframework.github.io/spin-python-sdk/v4/http/index.html#spin_sdk.http.Handler), overriding the `handle_request` method.
231+
In Python, the application must define a top-level class named `HttpHandler` which inherits from [http.Handler](https://spinframework.github.io/spin-python-sdk/v4/http/index.html#spin_sdk.http.Handler), overriding the `handle_request` method.
232232

233233
```python
234234
from spin_sdk import http
235235
from spin_sdk.http import Request, Response
236236

237-
class WasiHttpHandler030Rc20260315(http.Handler):
237+
class HttpHandler(http.Handler):
238238
async def handle_request(self, request: Request) -> Response:
239239
return Response(
240240
200,

content/v4/kv-store-api-guide.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ The key value functions are provided through the `key_value` module in the Pytho
131131
from spin_sdk import http, key_value
132132
from spin_sdk.http import Request, Response
133133

134-
class WasiHttpHandler030Rc20260315(http.Handler):
134+
class HttpHandler(http.Handler):
135135
async def handle_request(self, request: Request) -> Response:
136136
with await key_value.open_default() as store:
137137
await store.set("test", bytes("hello world!", "utf-8"))
@@ -168,8 +168,9 @@ class WasiHttpHandler030Rc20260315(http.Handler):
168168
- Return whether the specified key is present in the store
169169

170170
[`get_keys` **Operation**](https://spinframework.github.io/spin-python-sdk/v4/wit/imports/spin_key_value_key_value_3_0_0.html#spin_sdk.wit.imports.spin_key_value_key_value_3_0_0.Store.get_keys)
171-
- The underlying `get_keys` implementation no longer returns a list of strings in v4 of the SDK. Rather, due to the asynchronous nature of this method, it now returns a `Tuple` containing a [StreamReader](https://github.com/bytecodealliance/componentize-py/blob/1b3d2e936868307a48fb70941dcad71b54e844f8/bundled/componentize_py_async_support/streams.py#L101) and a [FutureReader](https://github.com/bytecodealliance/componentize-py/blob/1b3d2e936868307a48fb70941dcad71b54e844f8/bundled/componentize_py_async_support/futures.py#L11). You _must_ check when the stream ends, to determine if the stream ended normally, or was terminated prematurely due to an error.
172-
- However, a new [util](https://spinframework.github.io/spin-python-sdk/v4/util.html) module offers a convenience method called [collect](https://spinframework.github.io/spin-python-sdk/v4/util.html#spin_sdk.util.collect), which does return the list of keys, after reading them from the stream and handling the future, raising an exception if an error results. (You can use this helper to collect values from any `Tuple[StreamReader, FutureReader]` - it isn't specific to KV.)
171+
- Returns a `Tuple` containing a [StreamReader](https://github.com/bytecodealliance/componentize-py/blob/1b3d2e936868307a48fb70941dcad71b54e844f8/bundled/componentize_py_async_support/streams.py#L101) and a [FutureReader](https://github.com/bytecodealliance/componentize-py/blob/1b3d2e936868307a48fb70941dcad71b54e844f8/bundled/componentize_py_async_support/futures.py#L11). You _must_ check when the stream ends, to determine if the stream ended normally, or was terminated prematurely due to an error.
172+
173+
> If you're familiar with previous versions of the Python SDK, note that `get_keys` no longer returns a list. To get the keys as a list, use `await util.collect(await store.get_keys())`. See [collect](https://spinframework.github.io/spin-python-sdk/v4/util.html#spin_sdk.util.collect) for more details.
173174
174175
You can find a complete Python code example using the Key Value store in the [Spin Python SDK repository on GitHub](https://github.com/spinframework/spin-python-sdk/tree/main/examples/spin-kv).
175176

content/v4/mqtt-outbound.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ from spin_sdk import http, mqtt
9191
from spin_sdk.mqtt import Qos
9292
from spin_sdk.http import Request, Response
9393

94-
class WasiHttpHandler030Rc20260315(http.Handler):
94+
class HttpHandler(http.Handler):
9595
async def handle_request(self, request: Request) -> Response:
9696
with await mqtt.open("mqtt://localhost:1883?client_id=client001", "user", "password", 30) as conn:
9797
await conn.publish("telemetry", bytes("Eureka!", "utf-8"), Qos.AT_LEAST_ONCE)

content/v4/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ takes an HTTP request as a parameter and returns an HTTP response.
559559
```python
560560
from spin_sdk.http import Handler, Request, Response
561561

562-
class WasiHttpHandler030Rc20260315(Handler):
562+
class HttpHandler(Handler):
563563
async def handle_request(self, request: Request) -> Response:
564564
return Response(
565565
200,

content/v4/rdbms-storage.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,26 @@ addEventListener('fetch', async (event: FetchEvent) => {
146146

147147
> [**Want to go straight to the reference documentation?** Find it here.](https://spinframework.github.io/spin-python-sdk/v4/)
148148
149-
The code below is an [Outbound MySQL example](https://github.com/spinframework/spin-python-sdk/tree/main/examples/spin-mysql). There is also an outbound [PostgreSQL example](https://github.com/spinframework/spin-python-sdk/tree/main/examples/spin-postgres) available.
149+
The code below shows use of the [Postgres](https://spinframework.github.io/spin-python-sdk/v4/postgres.html) module and its [open](https://spinframework.github.io/spin-python-sdk/v4/postgres.html#spin_sdk.postgres.open) function for opening a connection to the database:
150150

151151
```python
152-
from spin_sdk import http, mysql
152+
from spin_sdk import http, postgres
153153
from spin_sdk.http import Request, Response
154154

155-
class WasiHttpHandler030Rc20260315(http.Handler):
155+
class HttpHandler(http.Handler):
156156
async def handle_request(self, request: Request) -> Response:
157-
with mysql.open("mysql://root:@127.0.0.1/spin_dev") as db:
158-
print(db.query("select * from test", []))
159-
157+
with await postgres.open("user=postgres dbname=spin_dev host=localhost sslmode=disable password=password") as db:
158+
print(db.query("SELECT * FROM test", []))
159+
160160
return Response(
161161
200,
162162
{"content-type": "text/plain"},
163163
bytes("Hello from Python!", "utf-8")
164164
)
165165
```
166166

167+
You can find a complete outbound PostgreSQL example in the [Spin Python SDK repository on GitHub](https://github.com/spinframework/spin-python-sdk/tree/main/examples/spin-postgres). There is also an [Outbound MySQL example](https://github.com/spinframework/spin-python-sdk/tree/main/examples/spin-mysql) available.
168+
167169
{{ blockEnd }}
168170

169171
{{ startTab "TinyGo"}}

content/v4/redis-outbound.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ To open a connection to a Redis instance, use the `redis.open` function. You can
125125
from spin_sdk import http, redis
126126
from spin_sdk.http import Request, Response
127127

128-
class WasiHttpHandler030Rc20260315(http.Handler):
128+
class HttpHandler(http.Handler):
129129
async def handle_request(self, request: Request) -> Response:
130130
with await redis.open("redis://localhost:6379") as db:
131131
print(await db.get("test"))

content/v4/redis-trigger.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,12 @@ The JavaScript/TypeScript SDK doesn't currently support Redis components. Pleas
9494

9595
{{ startTab "Python"}}
9696

97-
In Python, the handler needs to implement the [`SpinRedisInboundRedis300`](https://spinframework.github.io/spin-python-sdk/v4/wit/exports/index.html#spin_sdk.wit.exports.SpinRedisInboundRedis300) class, and override the `handle_message` method:
97+
In Python, the handler needs to implement the [`RedisHandler`](https://spinframework.github.io/spin-python-sdk/v4/wit/exports/index.html#spin_sdk.wit.exports.RedisHandler) class, and override the `handle_message` method:
9898

9999
```python
100100
from spin_sdk.wit import exports
101101

102-
class SpinRedisInboundRedis300(exports.SpinRedisInboundRedis300):
102+
class RedisHandler(exports.RedisHandler):
103103
async def handle_message(self, message: bytes) -> None:
104104
print(message)
105105
```

content/v4/serverless-ai-api-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ addEventListener('fetch', async (event: FetchEvent) => {
164164
from spin_sdk import http, llm
165165
from spin_sdk.http import Request, Response
166166

167-
class WasiHttpHandler030Rc20260315(http.Handler):
167+
class HttpHandler(http.Handler):
168168
async def handle_request(self, request: Request) -> Response:
169169
prompt="You are a stand up comedy writer. Tell me a joke."
170170
result = llm.infer("llama2-chat", prompt)

content/v4/sqlite-api-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ from spin_sdk import http, sqlite
165165
from spin_sdk.http import Request, Response
166166
from spin_sdk.sqlite import Value_Integer
167167

168-
class WasiHttpHandler030Rc20260315(http.Handler):
168+
class HttpHandler(http.Handler):
169169
async def handle_request(self, request: Request) -> Response:
170170
with await sqlite.open_default() as db:
171171
result = db.execute("SELECT * FROM todos WHERE id > (?);", [Value_Integer(1)])

0 commit comments

Comments
 (0)