Kopi is a tiny, simple programming language built for learning and experimenting. It is meant to be easy to read, easy to change, and easy to understand.
- Learn how a language works by reading the source code.
- Experiment with new ideas like functions, loops, and simple control flow.
- Build short programs without getting lost in complex syntax.
- Share ideas and grow a small community around language design.
Use the interpreter with a .kopi file:
kopi run examples/basics.kopiOr use Python directly:
python3 main.kopi examples/basics.kopiIn the Kopi dev container (Codespaces), the kopi command is automatically available in your PATH. After rebuilding the container, you can use:
kopi run examples/basics.kopi
kopi updateTo use kopi from anywhere outside the dev container, add the Kopi directory to your PATH:
export PATH="$PATH:/path/to/Kopi"Then you can run:
kopi run path/to/file.kopi
kopi updateTo update the Kopi language support extension in VS Code:
kopi updateThis will automatically uninstall and reinstall the latest version of the extension.
- Strings are written with double quotes:
"Hello, Kopi!"
- Numbers are written normally:
42-5
- Booleans are written as
trueorfalse. - Lists are written with square brackets:
[1, 2, 3]["one", "two", "three"]
Use let to create a new name for a value:
let count = 3
Change a value later using =:
count = count + 1
Use print(...) to show values:
print("Hello, world!")
print(count)
Use read(...) to ask the user for input and store their answer:
let name = read("What is your name? ")
print("Hello, " + name)
A function is a named block of code that can use values and return a result:
def add(a, b) {
return a + b
}
let total = add(5, 7)
print(total)
Use while to repeat code until a condition becomes false:
let count = 1
while (count <= 5) {
print(count)
count = count + 1
}
Use for to loop with a start, condition, and change:
for (let i = 0; i < 5; i = i + 1) {
print(i)
}
Use break and continue to control loop flow:
for (let i = 0; i < 5; i = i + 1) {
if (i == 2) {
continue
}
if (i == 4) {
break
}
print(i)
}
Access list items using [...] and find size with len(...):
let items = ["red", "green", "blue"]
print(items[0])
print(len(items))
Modify a list with append(...):
let numbers = [1, 2]
append(numbers, 3)
print(numbers)
len(value)— number of items in a list or length of a stringrange(n)— list of numbers from0ton-1range(a, b)— list of numbers fromatob-1range(a, b, step)— list by stepappend(list, value)— add a value to a listpop(list)— remove and return the last itempop(list, index)— remove and return a specific iteminsert(list, index, value)— insert a value into a listremove(list, value)— remove a value from a listkeys(dict)— list all dictionary keysvalues(dict)— list all dictionary valuesjoin(separator, list)— join list items into a stringsplit(text, sep?)— split a string into a listreplace(text, old, new)— replace text in a stringupper(text)— convert text to uppercaselower(text)— convert text to lowercasetype(value)— show the type namesum(list)— add all numbers in a listmin(list)— smallest value in a listmax(list)— largest value in a listsorted(list)— return a sorted listint(value)— convert a string to a numberstr(value)— convert a value to textany(list)— true if any item is truthyall(list)— true if every item is truthyabs(number)— absolute valuecopy(value)— shallow copy of a list or dictstartswith(text, prefix)— check string prefixendswith(text, suffix)— check string suffixround(number)orround(number, digits)— round a number
Kopi also supports:
null/nonefor missing values//single-line comments and/* ... */block comments- compound assignment:
+=,-=,*=,/= - membership checks with
in - dictionary literals and property access:
data["value"]anddata.value for (item in list)loops for easy iterationelse ifchains for clearer conditional logic
Use if and else to run different code paths:
let score = 10
if (score > 5) {
print("Great job")
} else {
print("Keep trying")
}
Add comments with #:
# This is a note for people reading the code
let message = "Hello"
This repo includes local VS Code language support in .vscode-ext/kopi-language-support.
To package and install the extension locally:
./scripts/package-extension.sh
code --install-extension kopi-language-support-1.0.0.vsix --forceTo uninstall the Kopi extension from VS Code:
code --uninstall-extension Kopi.kopi-language-supportTo reinstall it after uninstalling:
./scripts/package-extension.sh
code --install-extension kopi-language-support-1.0.0.vsix --forceAlternatively You can also keep the extension recommendation in your workspace so collaborators see it automatically:
.vscode/settings.jsonmaps.kopifiles to the Kopi language.vscode/extensions.jsonrecommends the Kopi extension
This interactive lesson teaches you the basics of Kopi by having you type in your own values! Run it and follow along:
python3 main.kopi examples/basics.kopiThe lesson covers:
- Variables and storing user input
- Loops that run multiple times
- Conditionals that make choices
- Functions that hold reusable code
Each section prompts you to enter information, then uses it in the code.
For a second example that shows lists, for loops, built-ins like len() and range(), and list indexing, run:
python3 main.kopi examples/advanced.kopimain.kopireads your file and sends it to the lexer, parser, and runtime.lexer.kopiturns text into small parts called tokens.parser.kopiturns tokens into a tree of statements and expressions.runtime.kopiruns that tree and produces output.
Kopi is best when people try new features and share what works.
- Add more lessons in
examples/ - Try adding
forloops orelse if - Improve error messages when the code is wrong
- Share your ideas for new Kopi syntax
A static website is included in the site/ folder for docs, tutorials, and community content.
From the repository root:
./kopi siteFrom inside the site/ folder:
./serve-site.shThen open http://localhost:8000 in your browser.
If the page still appears unchanged, refresh the browser or clear the cache so the latest HTML is loaded.