Skip to content

Repository files navigation

Nox Logo

Nox

A clean, expressive scripting language — built from scratch.

License: MITPythonPlatform


What is Nox?

Nox is a tree-walking interpreted language with its own lexer, parser, AST, and interpreter — written entirely in pure Python, with zero use of eval or exec. It's fast to hack on, easy to read, and designed to grow.

It has classes, traits, structs, async/await, decorators, pattern matching, C/C++ FFI, a built-in HTTP server, and a GitHub-powered package manager. The docs site runs as a Nox web app.


Getting Started

Requires Python 3.12+

git clone https://github.com/devnexe/nox
cd nox
python setup.py

The setup manager will guide you through everything:

 ███╗ ██╗ ██████╗ ██╗ ██╗
████╗ ██║██╔═══██╗╚██╗██╔╝
██╔██╗ ██║██║ ██║ ╚███╔╝
██║╚██╗██║██║ ██║ ██╔██╗
██║ ╚████║╚██████╔╝██╔╝ ██╗
╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝
The Nox Programming Language — Toolchain Manager
1) Install / setup environment
2) Show activate instructions
3) Build executable
4) Update dependencies
5) Exit

The Language

Variables & Types

x = 42
pi = 3.14
name = "nox"
flag = true
items = [1, 2, 3]
point = (10, 20)
mapping = {"key": "value"}
nothing = none

Functions

define add(a, b=0):
result a + b
define sum_all(*numbers):
total = 0
for n in numbers:
total = total + n
result total
square = lambda x: x * x
display add(3, 4) # 7
display sum_all(1,2,3) # 6
display square(9) # 81

Control Flow

if score >= 90:
display("A")
else if score >= 70:
display("B")
else:
display("F")
for item in ["apple", "banana", "cherry"]:
display(item)
repeat 5:
display("tick")
repeat count < 10:
count = count + 1
match status:
case 200, 201:
display("ok")
case 404:
display("not found")
else:
display("unknown")

Classes, Structs & Traits

class Animal:
define init(self, name):
self.name = name
define speak(self):
result "..."
class Dog(Animal):
define speak(self):
result self.name + " says: Woof!"
dog = Dog("Rex")
display dog.speak() # Rex says: Woof!
struct Point:
x: float
y: float
p = Point{x: 3.0, y: 4.0}
display p.x # 3.0
trait Serializable:
define to_json(self):
result ""
class Config:
implement Serializable
define to_json(self):
result json.encode({"version": "1.0"})

Error Handling

try:
data = fs.read("config.json")
except:
display("Config not found, using defaults")
finally:
display("Done")

Async / Await

async define fetch(url):
response = await http.get(url)
result response["json"]
task = create_task(fetch, "https://api.example.com/data")
data = await task
display data

Multiline Expressions

No backslash continuation — anything inside (), [], {} spans lines freely:

config = {
"host": "localhost",
"port": 8080,
"features": ["api", "web", "auth"]
}

Slicing

text = "Hello, World!"
display text[0:5] # Hello
display text[::-1] # !dlroW ,olleH
display text[-6:] # World!

Standard Library

ModuleWhat it does
mathabsminmaxfloorceilsqrtpow
stringsplitjoinlowerupperreplacestartswith
timenowsleep
jsonencodedecode
fsreadwriteexists
oscwdlistdir
httpservegetpostrequest
clibloadcall — C/C++ FFI via ctypes
compilercompile — compile C/C++ source to native library
processrunshell — spawn and control subprocesses
asynciocreate_taskgatherrunsleep

Package Manager

# Install from GitHub
python -m nox package install devnexe-alt/NoxWeb
# Short form (defaults to devnexe-alt org)
python -m nox package install NoxGram
# Full URL
python -m nox package install https://github.com/user/repo
# Manage
python -m nox package list
python -m nox package remove NoxWeb

Libraries live in Libraries/ next to your script or binary.


NoxWeb

A full web framework in Nox:

connect NoxWeb
app = NoxWeb.web()
app.static("static")
app.templates("templates")
@app.get("/")
define home(req):
result NoxWeb.render_template("index.html", {"title": "Nox"})
@app.get("/api/ping")
define ping(req):
result NoxWeb.json({"status": "ok"})
app.run(8080)

NoxGram

Telegram bots in Nox:

connect NoxGram
b = NoxGram.bot("YOUR_TOKEN")
b.command("start", define handler(ctx):
ctx["bot"].send_message(ctx["chat_id"], "Hello from Nox!")
)
b.poll()

C / C++ Integration

connect compiler
connect clib
# Compile C source → native library
compiler.compile("mylib.c")
# Load and call
lib = clib.load("mylib.dll")
value = clib.call(lib, "add", 10, 5)
display value # 15
# Or load an existing library via header
lib = clib.load("mylib.h")
display lib.get("greet")("Nox")

Auto-detects MSVC, GCC, or Clang. Strings auto-convert between Python str and C char*.


Process Control

connect process
p = process.run("ffmpeg", "-i", "input.mp4", "output.gif")
repeat p.alive():
for line in p.output():
display line
display "Exit: " + string.str(p.wait())
# or kill it
p.kill()

Folder Execution

python -m nox .
python -m nox my_project/
python -m nox examples/weather_app

Looks for __main__.noxmain.noxapp.nox automatically.


Error Messages

Traceback:
Error in main.nox at line 7 in process_data:
5 items = [1, 2, 3]
6
> 7 display items[10]
8
IndexError: list index out of range

Compile to Binary

python setup.py build

Produces a standalone nox.exe / nox — no Python needed on target. Place Libraries/ next to it.


Documentation

python -m nox documentation

Opens at http://localhost:8080. Available in English and Russian.


Architecture

ComponentFileRole
Lexernox/lexer.pyTokenizes source with indent/dedent tracking
Parsernox/parser.pyRecursive descent → AST
ASTnox/ast_nodes.pyDataclass-based node definitions
Interpreternox/interpreter.pyTree-walking evaluator with closures
CLInox/cli.pyEntry point, error rendering, package manager
JITnox/jit.pyOptional Numba acceleration for numeric ops
clibnox/clib.pyC FFI via ctypes
compilernox/compiler.pyC/C++ compilation via system compiler
processnox/process.pySubprocess control

Project Layout

nox/
├── nox/ # interpreter source
│ ├── lexer.py
│ ├── parser.py
│ ├── ast_nodes.py
│ ├── interpreter.py
│ ├── cli.py
│ ├── compiler.py
│ ├── process.py
│ ├── clib.py
│ ├── jit.py
│ └── info.cfg
├── documentation/ # docs web app
├── Libraries/ # installed packages
├── requirements.txt
├── setup.py # toolchain manager
└── LICENSE

MIT License — see LICENSE

Built with Python. No magic.

About

Nox is a clean, expressive programming language created from scratch in pure Python. Includes C/C++ FFI, async/await and its own ecosystem.

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages