Skip to main content

KSB — Kernel Script for Bots

Ultra-dense scripting language for AI agents. Fewer tokens than Python for tool scripts. Compiles to Python 3.

License: MIT Python 3.10+

@ max(a:i,b:i)->i {
  ? a>b { ^a } { ^b }
}
@ main()->i { ^ max(3,7) }

Dense form:

@max(a:i,b:i)->i{?a>b{^a}{^b}}
@main()->i{^max(3,7)}

Why KSB?

Problem for agents KSB
Long keywords burn tokens @ ^ ? * #
Huge stdlib surface Small agent runtime
Style noise ksb fmt + rigid grammar
Silent type mistakes ksb check optional types

Paste KSB.md into an agent system prompt (~400 tokens).

Install

From PyPI (after first publish):

pip install ksb
ksb -V

From source:

git clone https://github.com/semihbalan/ksb.git
cd ksb
pip install -e ".[dev]"
ksb -V

CLI

ksb run examples/hello.ksb
ksb run examples/match.ksb
ksb run examples/use_mod.ksb
ksb run examples/agent_kit.ksb

ksb build app.ksb -o app.py
ksb fmt app.ksb          # pretty-print to stdout
ksb fmt app.ksb -w       # write back
ksb check app.ksb        # typecheck
ksb parse app.ksb
ksb lex app.ksb

Language (cheat sheet)

Syntax Meaning
@ f(a:i)->i { ... } function
^ e return
= x e bind
? c {t} {f} if / else
* c { ... } while
* x:xs { ... } for-each
# e { p => v; _ => v } match
a | f pipe → f(a)
~ fs / ~ "lib/mathx" import runtime or local .ksb
T F N true / false / null

Patterns: _ · literals · bind n · [h,*t] · {ok:T, msg:m}

Types (optional): i f s b l m a

Runtime modules

Module Highlights
fs read, write, exists, list, mkdir, remove, copy, cwd
http get, post, put, delete, get_json, post_json
json parse, dump
sh run
env get, set
log info, err
time now, ms, sleep, iso
path join, dirname, basename, abs, ext
cli args, argc, arg
str split, join, trim, replace, contains, lower, upper
tool ok, err, wrap — agent result shapes

Local modules

// lib/mathx.ksb
@ add(a:i,b:i)->i { ^ a+b }

// app.ksb
~ "lib/mathx"
@ main()->i { ^ add(1,2) }

Functions from imported .ksb files are inlined at compile time (no main import).

Architecture

.ksb → lex → parse → [bundle local mods] → [typecheck] → codegen → Python 3
                                              ↓
                                    ksb.runtime (agent stdlib)

Development

pip install -e ".[dev]"
pytest -q

CI runs on every push (Python 3.10–3.13). See CONTRIBUTING.md and docs/publishing.md for release / PyPI.

Topics

ai · agents · compiler · language · llm · python · transpiler

License

MIT — free for humans and agents.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ksb-0.2.0.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ksb-0.2.0-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

File details

Details for the file ksb-0.2.0.tar.gz.

File metadata

  • Download URL: ksb-0.2.0.tar.gz
  • Upload date:
  • Size: 28.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ksb-0.2.0.tar.gz
Algorithm Hash digest
SHA256 392fc337e8b0ac0cb98c6f99108a4359f2417b6a24abcec84926eed2514e42e7
MD5 0681e82e2ac2b2cc119fac28495e1d52
BLAKE2b-256 38ea19d88c626409f3531fb75b429ab3e6f23df5c598a6f99a67d62694f2a68b

See more details on using hashes here.

Provenance

The following attestation bundles were made for ksb-0.2.0.tar.gz:

Publisher: publish.yml on semihbalan/ksb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ksb-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: ksb-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 28.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ksb-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ea5c6640f849951faf498eb7e7d8a042d6906e35ae552282e5f4e3909463637
MD5 0c1d000c3d18627341a0e32d574e9af4
BLAKE2b-256 312f7f2cc8bd5ab63d5f76bd4c7db76a551a8de75e31956901228f073b4954c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for ksb-0.2.0-py3-none-any.whl:

Publisher: publish.yml on semihbalan/ksb

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page