Nox
Download

Standard library

The standard library

The standard library is written in Nox itself (stdlib/nox/*.nox) with thin Zig shims wherever the operating system is involved. It ships with every compiler and is imported with import nox.<module> or from nox.<module> import …. Everything on these pages is part of the stable Nox API: signatures and documented behaviour do not change within 2.x.

How to read these pages#

Each module page states how to import it, the capability it needs, a reference table of every public function and class, runnable examples whose output is checked, and notes about limits and traps. Three conventions recur:

  • Qualified vs unqualified. Ordinary functions are called qualified (nox.strings.upper(s)); extern def bindings are never name-mangled, so the few of those (the libm functions in nox.math) are called unqualified. Each page says which.
  • Exceptions. Each module that can fail defines its own exception class (FsError, JsonError, …), a subclass of Exception. Import the class by name to catch it (from nox.fs import FsError); qualified names are not accepted in an except clause. The text of messages produced by the library is not part of the API.
  • Indexes. Positions are zero-based everywhere, including SQL parameter indexes.

Capabilities#

Every module has a capability set — the kind of authority it needs. In the default hosted profile all are available; the freestanding profile (kernels, no operating system) permits only modules with no capability requirement. nox.crypto and nox.time are finer-grained: only the functions that need entropy or a clock are marked.

Capability Meaning Modules
none pure computation strings, mathx, bigint, decimal, fraction, argparse, fnmatch, random, collections, bits, buffer, binary, path, console, json, toml, yaml, csv, regex, unicode, template, validate, url, gzip, tar, zip, zstd, protobuf, db, orm, router, reflect, web, mem, test, uuid, base64, jwt, ed25519, crypto, time
filesystem files and directories fs, glob, tempfile, sqlite, timezone, wasm
network sockets http, websocket, tls, smtp, postgres, mysql, redis, redis_cluster, grpc, grpc_server, udp, dns, safehttp
network + filesystem both transfer
process the process and its children os, process, signal, terminal
threads native threads thread, atomic
clock reading the system clock log (and the clock functions of time)
shared_memory cross-process memory sharedmem
libc_math the C math library math
entropy operating-system randomness the salt-generating functions of crypto

native and plugin are hosted-only (they are not on the freestanding allow-list). nox.base64 and nox.jwt are pure Nox and are available on freestanding and on a mobile target; nox.bytes, nox.unicode and nox.web are available on a mobile target too (not nox.unicode on freestanding, whose runtime has no Unicode tables). On a mobile target, nox.mysql and nox.postgres use drivers written in Zig over the operating system's sockets instead of libmysqlclient/libpq (see their pages for the TLS limits), while nox.http.serve_tls (including the file-descriptor and multicore TLS variants) and nox.http.serve_ws_tls are still rejected because they load libssl. The HTTP client, nox.tls, nox.websocket and nox.smtp stay available. nox.hpy is a preview package profile (nox-hpy-host-v1); it is not part of the stable 2.x API yet. See HPy host v1 and Freestanding.

The prelude#

Some names are available without any import: print, len, range, sorted, min, max, sum, abs, round, enumerate, zip, map, filter, input, the exception classes (Exception, ValueError, IndexError, KeyError, ZeroDivisionError, AssertionError, CancelledError), JsonValue, and the generic concurrency types (Task, Channel, …). They are documented in Built-in functions.

Modules by area#

Text and numbers#

Module Purpose
nox.strings split, join, trim, replace, search, padding, byte-level helpers
nox.math, nox.mathx floating-point mathematics (libm-backed / libc-free)
nox.bigint, nox.decimal, nox.fraction arbitrary-precision integers, exact decimals, exact rationals
nox.random pseudo-random numbers and shuffling
nox.time wall clock, sleeping, calendar date-times, monotonic intervals
nox.tasks task groups: add, wait, limit, cancel
nox.property seeded property-based testing with size shrinking and replay
nox.regex, nox.pcre2 regular expressions (groups, alternation, captures); PCRE2 with JIT
nox.unicode Unicode normalization (NFC/NFD/NFKC/NFKD) and Turkish case mapping
nox.template {{ name }} text templates, HTML-escaped by default

Data structures and binary data#

Module Purpose
nox.collections stack, queue, deque, set, counter, ordered map, LRU cache, heap, priority queue
nox.bits rotations, byte swaps, endianness, single-bit helpers
nox.buffer fixed-size byte buffers and spans
nox.binary cursor-based binary readers and writers
nox.bytes str to Buffer byte conversion (hosted)
nox.protobuf Protocol Buffers wire format: writer and reader (varint, zigzag, fixed, nested, packed)

Files, processes and the environment#

Module Purpose
nox.fs read, write, copy, rename, list, inspect
nox.path path manipulation
nox.os arguments, environment variables, working directory, exit
nox.process run external programs
nox.signal SIGINT/SIGTERM/… as flags a task can poll
nox.terminal TTY detection, size, raw mode, echo, raw input/output
nox.timezone IANA time zones: offset, abbreviation, DST, local ↔ UTC conversion
nox.console, nox.log levelled output without / with timestamps

Formats and encodings#

Module Purpose
nox.json, nox.yyjson, nox.toml, nox.yaml, nox.csv parsers and writers
nox.validate validate JSON against a schema
nox.url URLs, percent-encoding, query strings
nox.base64, nox.uuid, nox.gzip, nox.tar, nox.zip, nox.zstd, nox.brotli, nox.lz4, nox.xxhash Base64, UUIDs, compression and archives
nox.wasm Run WebAssembly modules (embedded interpreter, sandboxed, fuel and memory limits)
nox.ffi Callback[F] handles: lambdas and closures as C callbacks

Security#

Module Purpose
nox.crypto hashes, HMAC, secure randomness, password hashing
nox.ed25519 Ed25519 signature verification and key fingerprints
nox.jwt HS256 JSON Web Tokens

Networking and the web#

Module Purpose
nox.http HTTP client and server (TLS and WebSocket upgrade included)
nox.transfer stream HTTP bodies to and from files
nox.router path routing and middleware
nox.web cookies, CORS, rate limiting, request ids, access log, security headers
nox.websocket WebSocket client and server connection
nox.tls client TLS streams
nox.udp UDP datagram sockets (loopback/telemetry/discovery), fiber-friendly receive
nox.safehttp HTTP client safe for untrusted URLs: address checks on every redirect hop, DNS-rebinding proof
nox.ip IPv4/IPv6 parsing and classification (is_global, private/loopback/metadata...) for SSRF defences
nox.dns explicit DNS resolution (resolve(host)) for resolve-validate-connect SSRF defences; pairs with nox.http.request(..., connect_ip=...)
nox.smtp send e-mail

Databases#

Module Purpose
nox.db shared Row, Statement and the DbConnection protocol
nox.sqlite, nox.postgres, nox.mysql drivers
nox.grpc gRPC client over HTTP/2 (h2c or TLS): unary, streaming, bidirectional streams, metadata, mTLS, gzip
nox.grpc_server gRPC server on top of nox.http: unary, server and client streaming, status codes
nox.redis_cluster Redis Cluster client: hash slots, -MOVED/-ASK redirects, topology refresh
nox.redis Redis client: commands, Streams, scripts, AUTH/TLS
nox.orm parameterised CRUD helpers over any driver

Concurrency and low level#

Module Purpose
nox.thread worker threads and thread channels
nox.atomic atomic counters and flags shared between workers
nox.sharedmem shared memory between processes
nox.mem bulk typed-pointer operations and volatile access

Reflection, extensions and testing#

Module Purpose
nox.reflect decorator and class metadata
nox.native, nox.plugin load native plugins (NNI, Plugin API)
nox.test assertions and test suites

Third-party libraries#

Anything outside nox.* — web frameworks such as Nyx, database layers, utilities — comes from packages: see Packages and the noxpkg registry.