Kiri Developers

SDK

SDK quick start

This page takes a small Go web service and runs it as a module: check it, change two lines, run it, look at it in Kiri’s window and share it. The steps are the same in Rust, TypeScript and Python; only the two lines differ, and the API reference has them for each language.

Before you start

You need Kiri 1.0, on a Mac, Linux or Windows. The kiri command comes with it; see Install. You don’t need a WebAssembly toolchain: Kiri builds in its own builder, with the language version your project names.

The service lists orders from a SQLite database. Here it is as an ordinary Go program, in a folder called shop:

package main

import (
	"database/sql"
	"encoding/json"
	"log"
	"net/http"

	_ "github.com/mattn/go-sqlite3"
)

type Order struct {
	ID    int     `json:"id"`
	Total float64 `json:"total"`
}

func main() {
	db, err := sql.Open("sqlite3", "shop.db")
	if err != nil {
		log.Fatal(err)
	}
	db.Exec(`CREATE TABLE IF NOT EXISTS orders
		(id INTEGER PRIMARY KEY, total REAL)`)

	http.HandleFunc("/orders", func(w http.ResponseWriter, r *http.Request) {
		rows, err := db.Query("SELECT id, total FROM orders")
		if err != nil {
			http.Error(w, err.Error(), 500)
			return
		}
		defer rows.Close()
		out := []Order{}
		for rows.Next() {
			var o Order
			rows.Scan(&o.ID, &o.Total)
			out = append(out, o)
		}
		json.NewEncoder(w).Encode(out)
	})

	log.Fatal(http.ListenAndServe(":8080", nil))
}

Check the project

In the project’s folder, run kiri check. It reads go.mod, looks at every package the program uses, and says which ones work as WebAssembly and what to change for the rest. It changes nothing.

zsh
$ cd shop
$ kiri check .
  shop · Go 1.26 · 42 packages
  ✓ 41 packages work as WebAssembly
  ✗ github.com/mattn/go-sqlite3   needs cgo, which WebAssembly doesn't have
      main.go:18  sql.Open("sqlite3", "shop.db")    → kiri.DB()
  ✗ net/http listener              listens by itself
      main.go:41  http.ListenAndServe(":8080", nil) → kiri.Serve(nil)

  2 to change · no kiri.yaml yet: kiri check --write makes one
$ kiri check . --write
  ✓ wrote kiri.yaml: app shop · needs database sqlite, port 8080

--write makes a kiri.yaml from what the code uses now: the SQLite database and port 8080. It lists only what it saw, so the module starts with the least it needs.

app: shop
needs:
  database: sqlite        # kept by Kiri
  port: 8080

Change two lines

Replace the line that opens the database and the line that listens, then add the SDK with go get runkiri.com/go/kiri. The handler stays as it is.

 import (
-	"database/sql"
 	"encoding/json"
 	"log"
 	"net/http"

-	_ "github.com/mattn/go-sqlite3"
+	"runkiri.com/go/kiri"
 )

 func main() {
-	db, err := sql.Open("sqlite3", "shop.db")
-	if err != nil {
-		log.Fatal(err)
-	}
+	db := kiri.DB()
 	db.Exec(`CREATE TABLE IF NOT EXISTS orders …`)
 	...
-	log.Fatal(http.ListenAndServe(":8080", nil))
+	log.Fatal(kiri.Serve(nil))
 }

kiri.DB() returns a *sql.DB, the same type as before, so db.Exec, db.Query and rows.Scan don’t change. The error check goes, because kiri.DB() can’t fail: Kiri has already checked the database against kiri.yaml before your code starts. Run kiri check . again and it says ✓ 41 packages work as WebAssembly · 0 to change.

Run it

kiri run . builds the module and starts it. It stays in the foreground and prints the module’s logs and each request; Ctrl+C stops it.

zsh
$ kiri run .
  ◆ shop  building Go 1.26 → WebAssembly…
  ✓ built · uses db, port · kiri.yaml lists both
  ●  serving on :8080 · 2.1 MB · started in 1.2 ms · needs db, port
     http://shop.kiri.local · http://localhost:8080

  Logs show up below. Press Ctrl+C to stop.

  14:02:15  GET     200  /orders                3 ms

Open http://shop.kiri.local/orders in your browser, or curl it, and you get []: the database is there and empty. Kiri keeps it between runs, under the module’s name, so the rows you add are still there next time.

From a project to a running moduleYour projectgo.mod · main.gokiri.yamlKiri’s builderGo 1.26 → WebAssemblycached between buildsCheckedthe module uses db, portkiri.yaml lists bothbuildcheckcompile onceMachine codekept with the module,so it never compiles againshopserving on :80802.1 MB · started in 1.2 msYour browsershop.kiri.localloadHTTP
What kiri run does. Kiri builds the module from your project, checks that it uses nothing kiri.yaml doesn't list, and compiles it to machine code once. Starting it is loading that code: 1.2 ms here. Requests to shop.kiri.local or port 8080 go to the running module.
Flag What it does
--watch Builds and restarts the module each time you save a file. The database and the key-value store are kept.
-d Runs it in the background (the long form is --detach). kiri module logs shop -f follows its log, and kiri module stop shop stops it.
--port N Listens on port N instead of the one in kiri.yaml, for this run only.

kiri run with a folder builds and runs a module. With anything else, such as kiri run -d nginx, it’s Docker’s run, as before.

See it in the window

Running modules are listed under Modules, in the Kiri part of the sidebar. Each row has the module’s name and local address, its state, its port and its size, with Share and Stop. Click the name for its page: Overview, Logs, Permissions and Security.

Kiri
DockerContainersComposeImagesVolumesNetworksBuildsKiriModulesUSBShareSettings

Modules › shop

shopshop.kiri.localServing80802.1 MBShareStop
OverviewLogsPermissionsSecurity
Built from~/code/shopGo 1.26
Started14:02:11in 1.2 ms
May touchdatabase sqlite · port 8080
DatabaseSQLite, kept by Kiri48 KB
The shop module's page, opened from Modules in the sidebar. Its top row has its local name, state, port and size; Overview says what it's built from and what it may touch.

Logs shows the same lines as your terminal, with what your code writes through kiri.Log. Permissions lists what kiri.yaml allows and anything the module tried that it doesn’t; see kiri.yaml. Security has the module’s bill of materials and its vulnerability scan; see Supply chain and policy.

Share it

A module has a port like a container, so Kiri Share works on it. Press Share on its row, or give kiri share the module’s name:

zsh
$ kiri share shop

  ◆ Kiri Share  connecting to edge.runkiri.com…
  ●  linked   shop · localhost:8080
  ●  live     https://shop-4k2x.runkiri.cloud

  Requests show up below. Press Ctrl+C to stop sharing.

© 2026 Kiri · The SDK is open source under the Apache License 2.0 · Docs · runkiri.com