Skip to content

Standard Library

Import modules with from "std/<name>" import { symbols }.

Most utilities are namespaced: call a static on the namespace (Path.join, Json.parse, Math.sqrt) or a method on the value (s.trim(), dt.format()).

I/O & Filesystem

ModuleWhat it provides
std/ioreadStdin, writeStdout, File.openRead/.openWrite/.openAppend, f.readAll(), f.writeAll(), RAII file handles
std/fsreadFile, readLines, readDir, fileInfo, isDir/isFile, pathExists, writeFile
std/pathPath.join, Path.basename, Path.dirname, Path.ext, Path.stem
std/envEnv.get, Env.getOr

Networking

ModuleWhat it provides
std/netTCP, DNS, fetch with TLS
std/httpHTTP server with Hono-style router, context, middleware
std/htmlHTML escaping — Html.escapeText, Html.escapeAttr, Html.isSafeUrl
std/mimeMedia types by extension — Mime.fromPath, Mime.contentType
std/multipartmultipart/form-data parsing — Multipart.parse, Part.safeFilename

Data

ModuleWhat it provides
std/jsonZero-copy JSON parser — Json.parse, keyed accessors (.str(), .i64(), .f64(), .bool()), Json.stringify
std/arenaGenerational arena for cyclic/graph data with safe Handle<T>
std/setHashSet<T>s.add, s.contains, s.remove

CLI & System

ModuleWhat it provides
std/argparseCLI argument parsing with typed getters and --help generation
std/argsRaw CLI arguments — args(), getFlag, hasFlag
std/processCommand execution, Process.spawn/.wait()/.signal(), run, capture
std/signalPOSIX signal handling — onSignal, ignoreSignal

Data Formats

ModuleWhat it provides
std/csvCSV parsing with header support — Csv.parse, Csv.stringify
std/base64Base64 encode/decode — Base64.encode, Base64.decode
std/hexHex encode/decode — Hex.encode, Hex.decode
std/binaryFixed-width int/float codecs — Bytes.readU32Le, Bytes.writeI16Be, both byte orders

Date, Time & IDs

ModuleWhat it provides
std/timeWall clock, elapsed time, Duration arithmetic/parse/format, sleep
std/timerTimer, Ticker, recvTimeout, waitReadable/waitWritable
std/datetimeDate/time — DateTime.now/.fromEpoch, then dt.format(), weekdayName
std/uuidUUIDs — Uuid.v4, Uuid.v7, Uuid.parse

Concurrency

ModuleWhat it provides
std/runtimeTask.spawn, Promise / Promise.blocking, green scheduler
std/eventkqueue/epoll/IOCP readiness polling — the layer std/runtime drives
std/syncChannel, WaitGroup, AtomicI64, AtomicBool — all method-based
std/shardparallelMap, shatter — divide a buffer's ownership across cores, no copy, nothing shared

Database & Network

ModuleWhat it provides
std/sqliteSQLite3 bindings — dbOpen, dbQuery, dbExec, prepared statements
std/urlURL parsing — Url.parse, then u.queryGet, u.toString

Strings & Formatting

ModuleWhat it provides
std/stringString methodss.contains, s.split, s.replace, s.trim, case conversion
std/sealSealed — freeze a string so stored Spans can never be invalidated
std/fmtTemplate formatting (fmt1fmt4), padLeft/padRight, join
std/strconvparseInt, parseFloat, parseBool, radix conversions, formatFloat, quoteString/unquoteString
std/unicodeCharacter classification — asciiIsDigit, asciiIsAlpha, asciiToLower

Math & Random

ModuleWhat it provides
std/mathMath.abs, Math.min, Math.max, Math.pow, Math.sqrt, Math.log, trig
std/randomRandom.int, Random.float, Random.range, Random.shuffleI64

Utilities

ModuleWhat it provides
std/colorSGR text styling — Color.red, Color.green, Color.bold, etc.
std/regexRegular expression matching — Regex.compile, .isMatch, .find
std/sortSorting for Vec — sortI32, sortI64, sortStrings
std/testingassert, assertEqual, assertStrEqual
std/logLeveled structured logging — Log, Logger, LogLevel, LogFormat
std/memmmapAnon, mmapFile, Bump bump allocator

Cryptography

OpenSSL-backed hashing plus pure-Milo hashing, MAC, and token modules (no C codec dependency; constant-time and WCET-analyzable).

ModuleWhat it provides
std/cryptoCrypto.sha256, Crypto.sha1, Crypto.md5, and Crypto.aesGcmEncrypt/.aesGcmDecrypt (128/256-bit AES-GCM)
std/sha256Pure-Milo SHA-256 — Sha256.hash, Sha256.bytes
std/sha512Pure-Milo SHA-512 / SHA-384 — Sha512.hash, Sha384.bytes
std/sha1Pure-Milo SHA-1 — Sha1.hash, Sha1.bytes
std/hmacHMAC-SHA256 / 384 / 512 / SHA-1 — Hmac.sha256, Hmac.sha512Bytes
std/subtleConstant-time comparison — constantTimeEq
std/hkdfHKDF extract-and-expand (RFC 5869) — Hkdf.sha256
std/pbkdf2Password-based KDF (RFC 8018) — Pbkdf2.sha256
std/jwtJWT sign/verify (HS256/384/512) with claim validation — Jwt.signHS256, Jwt.verifyHS256, JwtVerifier
std/totpRFC 6238 TOTP / RFC 4226 HOTP one-time passwords — Totp.generate, Totp.hotp
std/base32Base32 encode/decode (RFC 4648) — Base32.encode, Base32.decode

Compression

Pure-Milo DEFLATE (RFC 1951) and the gzip / zlib / zip containers built on it.

ModuleWhat it provides
std/deflateCompress — Deflate.raw, Deflate.gzip, Deflate.zlib
std/inflateDecompress — Inflate.raw, Inflate.gzip, Inflate.zlib
std/zipRead ZIP archives — Zip.read (.zip/.jar/.epub/.docx)

HTTP Server Example

milo
from "std/http" import { Context, Response, Router, serveRouter }

fn homeHandler(ctx: &mut Context): Response {
    return ctx.html("<h1>Hello!</h1>")
}

fn jsonHandler(ctx: &mut Context): Response {
    let name = ctx.query("name") ?? "world"
    return ctx.json($"\{\"hello\": \"{name}\"}")
}

fn main(): i32 {
    var r: Router = Router.new()
    r.get("/", homeHandler)
    r.get("/api", jsonHandler)
    serveRouter(8080, r)
    return 0
}

Arena Example

For cyclic data (graphs, doubly-linked lists), use std/arena. Nodes reference each other via Handle<T> — typed indices — instead of pointers:

milo
from "std/arena" import { Arena, Handle, arenaNew, arenaAlloc, arenaModify }

struct DLNode {
    value: i64,
    prev: Option<Handle<DLNode>>,
    next: Option<Handle<DLNode>>,
}

fn main(): i32 {
    var arena: Arena<DLNode> = arenaNew()
    let a = arenaAlloc(arena, DLNode { value: 1, prev: Option.None, next: Option.None })
    let b = arenaAlloc(arena, DLNode { value: 2, prev: Option.Some(a), next: Option.None })
    arenaModify(arena, a, (n: DLNode) => {
        var updated = n
        updated.next = Option.Some(b)
        return updated
    })
    return 0
}