Wisp is in pre-release, self-hosted since GitHub suspended us. Install it, or see the changelog.

Wisp

Storage on Every Host

wisp::kv, wisp::blobs and wisp::sql are one API on every Wisp host. One environment variable per store picks where the data goes.

let kv = wisp::kv("SESSIONS");
kv.put_for(&format!("sess:{id}"), &user, 30 * 86_400).await?;   // TTL in seconds
let who: Option<String> = kv.get(&format!("sess:{id}")).await?;
let page = kv.list_page("sess:", "", 100).await?;                 // Page { keys, cursor }

let photos = wisp::blobs("PHOTOS");
photos.put("a.png", png, "image/png").await?;
let blob = photos.get("a.png").await?;                            // Blob { body, content_type }

let rows: Vec<Recipe> = wisp::sql("DB").all("select * from recipes where owner = ?", &[&id]).await?;

The full API (metadata, absolute expiry, get_json, put_json, list) is on Bindings.

A page can hold fewer than limit keys while more exist. Walk until the cursor is None. A page of an upstash store shows each name once. The same name may show on another page, because Redis SCAN may repeat a key. A list call of an fs store reads the folder once and keeps at most 1001 keys of the scan in memory.

Choosing a Driver

WISP_KV_<NAME> picks the driver of wisp::kv("NAME"), WISP_BLOB_<NAME> of wisp::blobs("NAME") and WISP_SQL_<NAME> of wisp::sql("NAME"). Nothing is opened until the first call, and an app that uses none carries none of the code. Wisp keeps the driver of each store name until the process stops, so name the stores in the code, not from request data.

WISP_KV_* / WISP_BLOB_* / WISP_SQL_*kvblobssqlRuns on
cf:BINDINGWorkers KVR2D1Cloudflare Workers and Pages
deno-kv, deno-kv:<path or url>yesyes, 64 KiB eachDeno, Deno Deploy
netlify-blobs, netlify-blobs:<store>yesyesNetlify Functions and Edge Functions
fs, fs:<dir>yesyesthe built-in server, wisp dev, containers
memoryyesyesthe built-in server (gone on restart)
upstash, upstash:<url>Redis over RESTevery host
s3:<endpoint>/<bucket>yesevery host
vercel-blob, vercel-blob:privateyesevery host
libsql://<host>, https://<host>, http://<host>yesevery host
d1-http:<account id>/<database id>yesevery host

With fs, one server process owns a data folder. Its first store call locks .wisp-store.lock in the folder until the process stops. A second process on the folder waits for WISP_STOP_DELAY + WISP_DRAIN + 5 seconds. Then its store call fails with a 503: fs:<dir>: another process uses it. The other calls on the folder wait with that call and get its result. After a failed wait, each store call on the folder fails at once with the same 503 for the same time. Then the next call waits again. A store call on another folder does not wait. On NFS or SMB, the lock may not hold.

An expired key reads as missing and is not listed. The get or list that finds it expired deletes its file, so the folder does not grow with expired keys. A put of the same key at that time keeps its file. When the file locks of the file system do not work, Wisp writes one log line and keeps the files of expired keys.

The last five drivers speak HTTP: the host's fetch on the edge, wisp::fetch on the built-in server. There an https store needs Wisp's tls feature (wisp = { features = ["tls"] }, off by default) or the first call answers a 500 naming it. wisp::fetch opens a connection per call, so keep hot keys in fs or memory. A store sends its token over https only. Plain http is for localhost, 127.0.0.1 and [::1], else the first call answers a 500: a token goes over https only (plain http is for localhost). This holds for upstash, vercel-blob, libSQL with a token, and s3: with a session token. Plain http to an s3: host that is not this machine sends the request bodies and the signatures in clear text. Use https.

Defaults per Host

HostUnset WISP_KV_* / WISP_BLOB_*Unset WISP_SQL_*
Cloudflarethe binding called NAME in wrangler.tomlthe D1 binding NAME
Deno DeployDeno KV (when there is no binding NAME)501
NetlifyNetlify Blobs, store NAME501
Vercelnone: set upstash (Vercel KV, Marketplace Redis) and vercel-blob501
Node, Bun, Azure (Node build)none: set upstash or s3:501
AWS Lambdafs under /tmp/wisp-data/storage, per instance: set upstash or s3:501
VPS, Docker, Fly, Railway, Render, Cloud Run, wisp devfs: $WISP_DATA/storage when WISP_DATA is set (memory when off), else .wisp/data501

A store with no driver answers a 500 on the first call naming the variable to set. It never panics. The message shows only the scheme and the host of the value, such as WISP_KV_X is redis://h.example:6379. A value with no :// shows only its driver word (fs, cf), else (hidden).

Settings of Each Driver

  • upstash: URL from UPSTASH_REDIS_REST_URL (or KV_REST_API_URL) unless the spec has one. Token from WISP_KV_<NAME>_TOKEN, UPSTASH_REDIS_REST_TOKEN or KV_REST_API_TOKEN. Keys are prefixed <length of NAME>:NAME:, so stores share a database without meeting. Metadata sits beside the key and no list shows it. A non-UTF-8 value is kept as \0wisp-b64: and its base64.
  • s3:<endpoint>/<bucket>: path-style, AWS Signature Version 4. Key from WISP_BLOB_<NAME>_KEY_ID (or AWS_ACCESS_KEY_ID) and WISP_BLOB_<NAME>_SECRET (or AWS_SECRET_ACCESS_KEY), optional WISP_BLOB_<NAME>_SESSION_TOKEN (or AWS_SESSION_TOKEN). Region from WISP_BLOB_<NAME>_REGION or AWS_REGION, else the endpoint: auto for R2, the region of s3.<region>.amazonaws.com, else us-east-1 (MinIO). Examples: s3:https://s3.eu-west-2.amazonaws.com/photos, s3:https://<account>.r2.cloudflarestorage.com/photos, s3:http://localhost:9000/photos.
  • vercel-blob: token from WISP_BLOB_<NAME>_TOKEN or BLOB_READ_WRITE_TOKEN (it names the store). A put overwrites in place, and a public store's CDN may serve the old blob for up to 60 s. Add :private for a private store, whose reads carry the token. VERCEL_BLOB_API_URL moves the API.
  • libsql://<host>: Turso or any libSQL server, over its HTTP pipeline. Token from WISP_SQL_<NAME>_TOKEN, sent over https only (a plain http:// address with a token is refused unless localhost, 127.0.0.1 or [::1]). A BLOB column reads as base64 text. An integer argument outside the 64-bit range of libSQL is a 500 that names it, so Wisp loses no digits. The 500 shows the first 20 characters of a longer value.
  • d1-http:<account>/<database>: D1 from outside Cloudflare, over its REST API. Token (with D1 edit) from WISP_SQL_<NAME>_TOKEN or CLOUDFLARE_API_TOKEN. Each id holds only letters, digits, - and _, so an id cannot change the path of the API. Else each call fails with a 500. It names which id (account or database) and its first refused character, never the rest of the id or the token: WISP_SQL_DB is d1-http: it is d1-http:<account id>/<database id>, and each id holds only letters, digits, - and _ (the account id has "?" at byte 1). An empty id gets (the database id is empty) or (the account id is empty).
  • deno-kv: keys are [kind, NAME, key] in the database Deno.openKv opens. Local Deno needs --unstable-kv.
  • netlify-blobs: the site store NAME (or the one the spec names), reached with the NETLIFY_BLOBS_CONTEXT Netlify gives each function.
  • fs:<dir>: one file per key under <dir>/<kv or blob>/<name>/, with escaped names so no key leaves the folder. A put writes a temporary file and renames, so a reader never sees half a value.

What Each Driver Keeps

  • Expiry (put_for, KvPut { ttl, expires }) holds on every driver. Cloudflare needs at least 60 s.
  • Lists come in key order. upstash, netlify-blobs, s3: and vercel-blob list names only, with no expiry or metadata. Netlify Blobs takes no page size. A Netlify Blobs key with a . or .. segment is an error.
  • An s3: or vercel-blob key that is empty or has a . or .. segment gets a 400. A list's prefix may be empty.
  • On every store, an empty metadata or content type reads back as None.
  • A Deno KV value is at most 64 KiB (65,536 bytes, with its metadata and type): a larger put answers 413. Keep larger blobs in s3: or vercel-blob.

Host Bindings Stay on Their Host

wisp::platform::call(binding, method, ...) reaches a Cloudflare binding (Workers AI, Queues, Durable Objects) and runs only there. Elsewhere it answers 501. Use the binding's HTTP API through wisp::fetch for code that must run off Cloudflare.

Is This Page Useful?

View This Page's Source

Type to search every docs page and heading.