Packages

Package Manager

Serez Code has a built-in package manager. Packages install into a ./packages/ folder in your project — one command, no config files needed.

Installing a package

sz install serez-ai
sz install serez-ui

This creates ./packages/serez-ai/ in your current directory. Packages are local to the project — nothing is installed globally.

Removing a package

sz uninstall serez-ai

Using a package

Import a package at the top of your script with its name:

import "serez-ai"

let model = new Sequential()
model.add(new Dense(2, 32, "relu"))
model.add(new Dense(32, 1, "sigmoid"))

serez-ai

A neural network library with a Keras-like API. Build, train, and run models in just a few lines.

A complete training loop

import "serez-ai"

Random.seed(42)

// XOR dataset
let X = [[0.0, 0.0], [0.0, 1.0], [1.0, 0.0], [1.0, 1.0]]
let y = [[0.0], [1.0], [1.0], [0.0]]

// Build the network
let model = new Sequential()
model.add(new Dense(2, 16, "relu"))
model.add(new Dense(16, 1, "sigmoid"))

// Train
let opt  = new Adam(0.01, 0.9, 0.999)
let loss = model.fit_opt(X, y, new BCE(), 1000, opt)

out "Final loss: {loss}"

// Predict
let pred = model.forward([[1.0, 0.0]])
out "XOR(1, 0) = {pred[0][0]}"   // → ~0.97

Available layers

LayerWhat it does
Dense(in, out, activation)Fully connected layer. Activations: relu, sigmoid, tanh
Conv2D(filters, kernel, stride, padding)2D convolutional layer for image data
LSTM(input_size, hidden_size)Long Short-Term Memory for sequences
Attention(d_model, n_heads)Multi-head self-attention (Transformer block)
BatchNorm(features)Batch normalization — stabilizes training
Dropout(rate)Randomly zeros activations during training

Optimizers & loss functions

// Optimizers
let opt1 = new Adam(lr, beta1, beta2)
let opt2 = new SGD(lr)
let opt3 = new Momentum(lr, momentum)

// Loss functions
let loss1 = new MSE()    // Mean Squared Error
let loss2 = new BCE()    // Binary Cross-Entropy

// Train with optimizer
let final_loss = model.fit_opt(X, y, new BCE(), epochs, new Adam(0.01, 0.9, 0.999))

Tensors & autodiff

import "serez-ai"

// Create tensors
let a = new Tensor([[1.0, 2.0], [3.0, 4.0]])
let b = new Tensor([[2.0, 0.0], [1.0, 3.0]])

// Operations — gradients tracked automatically
let c = Autodiff.add(a, b)
let d = Autodiff.mul(a, b)
let e = Autodiff.relu(c)

// Backward pass
Autodiff.backward(e)

out a.grad   // gradients of a

serez-ui

A retained-mode terminal UI library. Build interactive TUIs with composable widgets — no ANSI dependencies.

import "serez-ui"

let app = new App()

let header = new Text("My App", "bold")
let items  = new VStack([
    new Text("Item 1"),
    new Separator(),
    new Text("Item 2"),
    new Spacer(),
    new Text("Item 3"),
])

let layout = new Box(
    new VStack([header, items]),
    { border: true, padding: 1 }
)

app.render(layout)

Available widgets

WidgetWhat it renders
Text(content, style?)A line of text, with optional bold/dim/italic styling
Box(child, options?)A bordered container. Options: border, padding, width
VStack(children)Arranges children vertically
HStack(children)Arranges children horizontally
Separator()A horizontal divider line
Spacer()Flexible space that fills available room