wispfnDocs
Function SDK

Key-value storage — get, set, delete, incr and list.

import { kv } from 'wisp';     // async: await every call
from wisp import kv            # synchronous

Guide: Key-value.

#kv.get(key)

const value = await kv.get('user:42');          // value or null
value = kv.get("user:42", default=None)

#kv.set(key, value, options?)

Stores any JSON value. ttl (seconds) makes it expire.

await kv.set('session:abc', { userId: 42 }, { ttl: 3600 });
kv.set("session:abc", {"userId": 42}, ttl=3600)

#kv.delete(key)

await kv.delete('session:abc');

#kv.incr(key, by = 1, options?)

Atomically adds by and returns the new number. Missing keys start at 0. Accepts ttl like set.

const n = await kv.incr('views:home');
const left = await kv.incr('credits:42', -1);
n = kv.incr("views:home")

#kv.list(options?)

Lists keys in key order.

OptionDefaultDescription
prefix""Only keys starting with this
limit100Up to 1,000
cursornullFrom the previous page

Returns { items: [{ key, value, expiresAt }], cursor }; cursor is null / None on the last page.

let cursor = null;
do {
  const page = await kv.list({ prefix: 'todo:', cursor });
  for (const { key, value } of page.items) console.log(key, value);
  cursor = page.cursor;
} while (cursor);
page = kv.list(prefix="todo:", limit=100)

#Limits

Keys up to 512 bytes; values up to 256 KB. Writes fail with Storage is full when the workspace is over its storage quota.