Version 0.54.0 is out

One readable language for scripts, sites and desktop apps.

KScript runs a terminal script, renders a live web page and draws a native window, all from one small binary on Windows, macOS and Linux.

hello.kscript
import KScript.Terminal

input(into: name) "What's your name? "
echo "Hello, { $name->trim()->title() }!"
What's your name?  joan
Hello, Joan!

Install

One native program, kscript, on your PATH. Nothing else to install first.

curl -fsSL https://raw.githubusercontent.com/kylepantall/kscript/master/install.sh | sh

Then run kscript ide install for your editor, or kscript make project my-app to start. More ways to install

Scripts

Scripts that read like what they do

Real values with methods on every one, pipes, lambdas, try and catch, and functions you call like commands. This one lists everything over 1 MB in a folder, largest first.

The language
big-files.kscript
import KScript.IO
import KScript.Terminal

$folder = $args[0] ?? @known_folder(downloads)
$big = @files($folder, pattern: '*', recursive)
  |> filter(fn(f) => $f.size > 1000000)
  |> sort(by: fn(f) => -$f.size)

for f in $big {
  echo "{ @bold($f.name) }  { ($f.size / 1000000)->round(digits: 1) } MB"
} else {
  echo "Nothing over 1 MB in {$folder}."
}

Data

Say what the data looks like, once

Declare a type and the response is checked and turned into records your editor knows the fields of. Every mismatch is reported at once, with its JSON path.

Types and validation
stars.kscript
import KScript.Net

type Repo {
  name: string
  stars: int from stargazers_count
  owner: string from owner.login
}

$url = 'https://api.github.com/repos/kylepantall/kscript'
$repo = @api($url)->check()->convert(from: json, as: Repo)
echo "{$repo.name} by {$repo.owner} has {$repo.stars} stars"

Web pages

Pages that react, with no JavaScript

Put a live block in a page and its buttons, inputs and forms run KScript on the server. Only that block is redrawn. The state is signed and travels with the page, so the server keeps nothing between requests.

Web pages
todos.html
<live id="todos">
  <state name="todos" value="[]" />
  <state name="draft" value="''" />

  <form on-submit="add: $draft, to: $todos, set: $draft, to: ''">
    <input @bind($draft) placeholder="What needs doing?">
    <button>Add</button>
  </form>

  <ul>
    <for each="t" in="$todos"><li>{$t}</li></for>
    <else><li>Nothing yet.</li></else>
  </ul>
  <p>{ $todos->count() } to do</p>
</live>

Desktop apps

Native windows, still just KScript

A Window block opens a real window on macOS, Windows or Linux, and is redrawn after every handler. kscript compile turns it into an app that runs without kscript.

Desktop apps
counter.kscript
import KScript.UI

Window(title: 'Counter', width: 320, height: 200) {
  $count = 0
  Text(size: 32) "{$count}"
  Button(variant: primary, on_click: $count += 1) "Add one"
}

Why KScript

01

Learn it once

Scripts, pages and apps run on one interpreter, so a function you write for a script works in a page unchanged.

02

Mistakes show before it runs

Unknown names, bad attributes, missing imports and syntax errors are reported before the first line runs, with what to write instead.

03

An editor that knows your code

Completion knows the type of every value, including what your own functions return. Errors show as you type.

04

One binary, every OS

A native program that needs no .NET and starts in milliseconds. Scripts behave the same on all three platforms.

05

No build step

No node_modules, no virtual environment and no bundler. Save the file and run it.

06

Batteries included

Files, HTTP, databases, sign-in, mail, queues and documents come as packages, loaded only when a script imports them.

Import what you use

The core language is always there. Everything else is a package a script imports, and a terminal script never loads the web server.

  • KScript.TerminalPrompts, menus, confirmations, file pickers and colours
  • KScript.IOFiles, folders and paths
  • KScript.NetHTTP requests and downloads
  • KScript.HttpRoutes, controllers and middleware
  • KScript.WebPages, layouts, components and live blocks
  • KScript.DataModels, queries and migrations on SQLite, Postgres and MySQL
  • KScript.AuthAccounts, passwords, passkeys and sessions
  • KScript.UINative desktop windows
  • KScript.DocumentPDF, Word and LaTeX papers, reports and invoices
  • KScript.AILanguage models, with Claude
  • KScript.QueueBackground jobs with retries
  • KScript.MailEmail over SMTP, queued or now
  • KScript.MathMaths, random numbers and statistics
  • KScript.MarkdownMarkdown to HTML
  • KScript.CacheMemory and file caches, and ETags
  • KScript.TestTests for kscript test

Everything else is built in

Generators, a test runner, a linter, a formatter, a server and a compiler all come with kscript. Tests are KScript too.

tests/greeting.test.kscript
test(name: 'greets by name') {
  expect(@greeting('Joan'), equals: 'Hello, Joan!')
}
Terminal
kscript make project my-app
A web and desktop app with a layout, a live page, scripts and tests
kscript serve
Run your site on your computer
kscript test
Run the tests in tests/
kscript check
Report problems in every script and page, for CI
kscript fmt
Tidy every script and page
kscript compile --target all
Programs for macOS, Windows and Linux that run without kscript
kscript ide install
Add the extension to VS Code, Cursor, VSCodium or Windsurf
kscript docs
These docs, offline, with examples you can run

Write your first script in ten minutes