Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Appendix F: The Standard Library Index

Every module in the standard library, what it is for, and where the book covers it. All of them are reachable with a bare import, with no package manager and no dependency to add.

Each module’s source is in libs/, and every public function in it carries a doc block stating its parameters, its defaults and its edge cases.

Data and Serialisation

ModuleWhat it is forBook
jsonencode, decode, read and write JSON13
yamlparse YAML, with anchors, tags and multi-document streams13
tomlparse and write TOML, and edit one without disturbing its layout13
csvread and write CSV, with dialect detection13
structpack and unpack binary layouts10
base64Base64 encode and decode10
convertbase, hex, binary, octal and unicode conversions13
compressdeflate, zlib, gzip, zstd, lz4, bzip2, brotli, tar, zip, checksums10

Text and Markup

ModuleWhat it is forBook
htmla WHATWG-conformant parser, a DOM and CSS selectors13
wiretemplating, with directives as HTML attributes14
urlparse, build and percent-encode URLs13
mimedetect a media type from a name or from content13
colorsANSI terminal colour, with graceful degradation13

Time

ModuleWhat it is forBook
datedates, times, formatting, parsing and IANA time zones13

Cryptography and Identity

ModuleWhat it is forBook
hashdigests and HMACs, plus PBKDF210
bcryptpassword hashing13
cryptoRSA signing and HKDF13
uuidUUID versions 1, 3, 4, 5, 6, 7 and 813
jwtsign, verify and decode JSON Web Tokens, with JWKS13

Structure and Validation

ModuleWhat it is forBook
validatea fluent schema builder13
typeschecked coercion between types13
setan ordered set with the usual algebra13
enumnamed constants from a list or a dictionary13
arraytyped fixed-width numeric arrays, Int8 through Double13

The System

ModuleWhat it is forBook
osprocesses, filesystem, paths, environment, signals9
enva .env file into the environment, and typed values back out19
iostandard streams, the terminal, and in-memory files9, 10
statthe S_IS* predicates over a file mode13
argsa command-line parser with subcommands and --help20
loglevelled, structured logging with pluggable transports13
isolateOS-thread concurrency, channels and broadcasts11
fficalling C and Rust libraries, callbacks, and linking static libraries26

Testing

ModuleWhat it is forBook
testsuites, matchers, test doubles, snapshots and reports23

Databases

ModuleWhat it is forBook
sqlone contract for every relational database, with SQLite, PostgreSQL and MySQL adapters17

Mail

ModuleWhat it is forBook
mailmessages, SMTP, IMAP and POP3, both server ends, and DKIM18

The Network

ModuleWhat it is forBook
netTCP, UDP, unix sockets, TLS, DTLS, addresses and polling12
httpan HTTP/1.1 and HTTP/2 client and server15
rpcJSON-RPC 2.0 over HTTP, WebSockets, sockets and streams, both ends28

Graphics

ModuleWhat it is forBook
imaginedecode, draw, filter and encode images16

Numbers

ModuleWhat it is forBook
maththe mathematical constants4

Metaprogramming

ModuleWhat it is forBook
zurilexing, parsing, compiling and runtime reflection21

Packages and Their Submodules

Most of the larger modules are packages: a directory whose index.zu re-exports what its parts make public. import http reaches almost all of http without naming a submodule. Import a submodule directly when you want only that part of it, or when a name would otherwise collide.

array

One module per element width, each exporting a single class.

SubmoduleClassElement
array.int8Int8Arraysigned 8-bit
array.uint8UInt8Arrayunsigned 8-bit
array.int16Int16Arraysigned 16-bit
array.uint16UInt16Arrayunsigned 16-bit
array.int32Int32Arraysigned 32-bit
array.uint32UInt32Arrayunsigned 32-bit
array.int64Int64Arraysigned 64-bit
array.uint64UInt64Arrayunsigned 64-bit
array.floatFloatArray32-bit float
array.doubleDoubleArray64-bit float

compress

SubmoduleWhat it is for
compress.deflateraw DEFLATE streams
compress.zlibDEFLATE with a zlib header
compress.gzipDEFLATE with a gzip header and trailer
compress.zstdZstandard, levels 1 to 22
compress.lz4LZ4, block and frame formats
compress.bzip2bzip2
compress.brotliBrotli
compress.tarreading and writing TAR archives
compress.zipreading and writing ZIP archives
compress.checksumCRC32, CRC32C, Adler-32

ffi

SubmoduleWhat it is for
ffi.errorsevery error the module raises, under FfiError
ffi.typesType, and the struct, union and enum builders
ffi.pointerPointer: native memory and access through it
ffi.libraryLibrary: a loaded shared library
ffi.declareDeclarations: C and Rust source read into types and signatures
ffi.callbackCallback: a Zuri function behind a C function pointer

html

SubmoduleWhat it is for
html.tokenizerthe WHATWG tokenizer: text in, tokens out
html.parsertree construction: tokens in, a document out
html.nodethe document tree and everything you can do to it
html.selectorfinding nodes with CSS selectors
html.serializewriting a document back out, minified or pretty
html.entitiesnamed character references, both directions
html.elementsthe element tables tree construction consults
html.namespacesthe five namespace URIs the parser deals in

http

SubmoduleWhat it is for
http.clientHttpClient, the request side
http.serverHttpServer, the listening side
http.workerserving across several isolates
http.routermatching a method and path to a handler
http.middlewareCORS, access logging, security headers, and the rest
http.requestthe request object handlers receive
http.responsethe response object handlers return
http.headersHeaders, with the field-name rules of RFC 9110
http.cookiesCookie and CookieJar
http.sessionserver-side sessions, and the stores that keep them
http.session.sqlkeeping sessions in a relational database
http.bodyreading and writing message bodies
http.multipartmultipart/form-data, including file uploads
http.filesserving files from disk, with ranges and caching
http.streamchunked and streaming transfers
http.sseserver-sent events
http.websocketthe WebSocket protocol
http.proxyforwarding requests to another server
http.negotiateparsing Accept-style headers
http.statusthe IANA status codes and their reason phrases
http.h1the HTTP/1.1 wire format
http.errorsthe module’s error hierarchy

imagine

SubmoduleWhat it is for
imagine.imageImage, the pixel buffer everything else operates on
imagine.canvasdrawing: lines, shapes, fills, text
imagine.colorColor, and conversion between colour spaces
imagine.filtersblur, sharpen, convolution, and the rest
imagine.fontloading and measuring fonts
imagine.strokefontthe built-in stroke font, with no file to load
imagine.formatsdecoding and encoding PNG, JPEG, GIF, WebP and more
imagine.animationmulti-frame images
imagine.constantsthe named constants the module understands
imagine.errorsthe module’s error hierarchy

io

SubmoduleWhat it is for
io.bytesioBytesIO, a file-shaped object backed by memory
io.ttyterminal control: raw mode, size, cursor

isolate

SubmoduleWhat it is for
isolate.channelbounded multi-producer, multi-consumer queues
isolate.broadcastone-to-many publish and subscribe
isolate.errorIsolateError

jwt

SubmoduleWhat it is for
jwt.coreencode(), decode(), sign(), verify()
jwt.signerSigner, a reusable configured signer
jwt.verifierVerifier, a reusable configured verifier
jwt.tokenthe Token object a complete decode returns
jwt.jwksresolving a signing key from a JSON Web Key Set
jwt.codecalgorithm identifiers and the low-level encoding
jwt.errorsthe module’s error hierarchy

log

SubmoduleWhat it is for
log.loggerthe module-level info(), warn(), error() and friends
log.levelthe LogLevel enum and the default level
log.transportTransport, the base class every sink extends
log.consoleConsoleTransport, the default
log.fileFileTransport, with size-based rotation
log.dispatchconfiguring which transports receive what

net

SubmoduleWhat it is for
net.tcpTcpSocket and TcpStream
net.udpUdpSocket
net.unixUnixStream, over a path rather than an address
net.tlsTLS over a TCP stream
net.dtlsDTLS over a UDP socket
net.ipparsing, formatting and classifying IP addresses
net.addrSocketAddrV4 and SocketAddrV6
net.pollasking which of a set of sockets is ready

os

SubmoduleWhat it is for
os.pathjoining, resolving and comparing path strings
os.fsdirectories, permissions, symlinks, globbing
os.envreading, writing and listing environment variables
os.processprocess identity, subprocesses, signals
os.systemfacts about the process, the runtime and the machine
os.tempfilethe temporary directory, and scratch files in it

rpc

SubmoduleWhat it is for
rpc.messageRequest, Notification, Response, and reading and writing them as JSON
rpc.errorRpcError, the codes the specification defines, and the module’s other errors
rpc.serviceService and the Context its handlers are given
rpc.httphttp_handler() and HttpClient, JSON-RPC over HTTP
rpc.framingHeaderFraming, LineFraming and MessageFraming, telling messages apart
rpc.transportthe transports, WebSockets among them, and pipe() between isolates
rpc.endpointEndpoint, a service on a connection
rpc.serverserve(), an endpoint for every connection to a listening socket

sql

SubmoduleWhat it is for
sql.driverthe contract an adapter implements, and the capability flags
sql.errorsevery error a database raises, under one root
sql.paramsrewriting ? and :name into whatever an engine wants
sql.typeshow Zuri values and database values correspond
sql.decimalDecimal, for a column a float must not hold
sql.resultResultSet and ExecResult
sql.cursorreading a result a row at a time
sql.statementa statement compiled once and run many times
sql.transactionTransaction, and the savepoints inside it
sql.connectionthe Connection a program holds
sql.crudbuilding the four statements that are always the same
sql.schemaasking a database what is in it
sql.poolkeeping connections open and lending them out
sql.sqlitethe SQLite adapter, and its blobs, backups and hooks
sql.postgresthe PostgreSQL adapter, and LISTEN/NOTIFY
sql.mysqlthe MySQL and MariaDB adapter

mail

SubmoduleWhat it is for
mail.errorsevery error the mail stack raises, under one root
mail.addressreading and writing the addresses in a header
mail.headersthe header block, in order and without regard to case
mail.encodingthe encodings a header and a body use
mail.contentContent-Type and Content-Disposition
mail.messagea message, its MIME tree, and building one
mail.dkimsigning a message and checking a signature
mail.saslthe authentication mechanisms all three protocols share
mail.streama line-oriented connection, and negotiating TLS over one
mail.smtpthe sending and receiving ends of SMTP
mail.imapthe client and server ends of IMAP, and where mail is kept
mail.imap.parserthe IMAP grammar
mail.imap.storeMailStore, MaildirStore and MemoryStore
mail.pop3the client end of POP3
mail.poolrunning a mail server on more than one connection at once

test

SubmoduleWhat it is for
test.expectExpect and every matcher on it
test.runnercollecting the declarations and running them
test.reporterReporter, and the seven built-in ones
test.resultCase, Suite, Failure and Summary
test.mockMock, mock() and spy_on()
test.snapshotthe snapshot store and its file format
test.conductdiscovering and running a directory of test files
test.diffstructural equality, and rendering what differs
test.formatrendering any value for a failure message
test.sourcereading a stack trace back to the failing line
test.styleterminal colour, symbols and width
test.errorAssertionError and TestSetupError
test.contextwhat is true while one test is running

validate

SubmoduleWhat it is for
validate.validatorsthe one-line entry points, one per rule
validate.validatorValidator, the fluent builder
validate.schemaSchema, validating a whole dictionary at once
validate.ruleRule, the base class custom rules extend
validate.rulesevery built-in rule

wire

SubmoduleWhat it is for
wire.compileturning a parsed template into an instruction tree
wire.renderwalking a compiled template and writing the page
wire.expressionthe language between {{ and }}
wire.filtersthe filters every template starts with
wire.escapecontext-aware escaping
wire.loaderresolving the path in an x-include
wire.normalizerewriting the pseudo elements before parsing
wire.valueshow a template reads the values it is given
wire.constantsthe directive names Wire reserves
wire.errorsthe module’s errors, and the locations they carry

zuri

SubmoduleWhat it is for
zuri.tokentokenize(), and the Token type it returns
zuri.astparse(), and the Node type it returns
zuri.compilecompile(), and the Instr type it returns
zuri.reflectinspecting a live function, class, module or instance

Shadowing a Module

A file in ./.zuri/libs/ shadows a standard library module of the same name, because that directory is searched first. See The Module System.