An embeddable scripting language for Python
Let your users script your Python application. Koskript parses and runs small scripts inside a KoskriptRuntime, and any Python value you expose becomes available to them.
Install
pip install -U koskript
The default parser ships with lark as a dependency. Prefer zero dependencies? Use the experimental native parser: KoskriptRuntime(native_parser_experiment=True).
Run a script
from koskript import KoskriptRuntime
runtime = KoskriptRuntime()
runtime.execute("""
const names = ["Ana", "Luis"]
array.each(names, (name) { print("hello " + name) })
""")
hello Ana
hello Luis
Expose your own API
Any Python callable works out of the box — no wrappers to write by hand:
runtime = KoskriptRuntime({"double": lambda x: x * 2})
runtime.execute("return double(21)") # 42
What the language looks like
class Counter {
private count = 0
constructor() { this.count = 1 }
public fn bump() {
this.count = this.count + 1
return this.count
}
}
const c = new Counter()
print(c.bump() + c.bump()) # 5
error HttpError (err, status) {
err.message = "request failed"
err.status = status
}
try {
throw HttpError(404)
} catch e {
print(e.status) # 404
}
What it gives you
local / const per block; lambdas capture their defining scope.
fn, lambdas, recursion, wrappers with @decorator.
Inheritance, visibility, static members, constructors, super.
if / elseif / else; while, for, foreach.
error, throw, try / catch / finally.
Modules, namespaces, stdlib (array, map, string, math, json…), Python interop.
Documentation
| Document | What it covers |
|---|---|
| Getting started | Installation, first script, a complete example |
| Language reference | Types, variables, operators, control flow, functions, modules, strings, bytes |
| Classes | Inheritance, visibility, static members, constructors, super |
| Standard library | Core builtins and the map, array, string, bytes, math, json namespaces |
| Python interop | Exposing Python values, callables and classes to scripts |
| Embedding guide | KoskriptRuntime, run(), error handling, stdlib setup |
| Roadmap | What is done, what is planned, known limitations |
Koskript is in early development; the language and its API may change between releases. License: MPL-2.0.