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

Standard library

The standard library ships inside the compiler: no checkout, cache or network. You add a dependency, import by stable id, and set the project profile the package requires.

Find a function

Do not memorize names. Ask the installed compiler:

semaprax help library                    # the whole catalog, offline
semaprax help library compare            # one entry, about 200 bytes
semaprax help library std.core.compare   # by stable id

An entry shows the stable id, dependency row, required profile, signature, effects and contracts. The generated catalog is Standard library catalog; the machine-readable form is std/catalog.json.

Use a package in three steps

# 1. semaprax.toml: depend on the package
[dependencies]
std.core = "^0.1.0"

# 2. set the profile the entry requires (omit it for `scalar`)
[package]
profile = "owned-data-api.v1"
// 3. import by stable id, right after the module line
module app.using_std;

use function @id("std.core.min") from std.core as min;

Every bundled package is at version 0.1.0. An unknown package or an unsatisfied range fails with SPX-J121. If you call a standard-library name without importing it, the error prints the exact dependency and use lines to add (for example for min). Spell the type argument of generic calls (vec_push<i64>(...)). Pick the profile with Choose a project profile.

Every package

47 packages, all marked partial in the catalog: each works on the interpreter, native C11 and Core Wasm for its listed profile, and each has a conformance module. “Functions” counts declarations in the catalog entry.

PackageProfileFunctionsWhat it gives you
std.agentowned-data-api.v117Task, Context, Observation and Outcome records, plus stage-transition and retry helpers for agent loops.
std.asyncuseful-data.v16Wait and retry arithmetic: clamp a wait, next timeout, remaining time, stream end.
std.authowned-data-api.v148Secret, Identity and Authorization records, constant-time byte compare, session-state rules (expiry, rotation).
std.bytesuseful-data.v120Byte-slice helpers: get_or, index_of, count, prefix and suffix tests, u16/u32 reads, trimming, fields.
std.collectionsowned-data-api.v18Bounded Vec operations over Copy scalars: with_capacity, push, len, capacity, get, set, clear, reserve_exact.
std.corenone (scalar)12compare, min, max, clamp, in_range, bool and i64 conversion, xor, implies.
std.data.csvuseful-data.v18CSV field scanning, quote balance and record well-formedness.
std.data.jsonuseful-data.v112JSON scanning primitives: whitespace, hex, escapes, string ends, failure offsets.
std.data.json.decowned-data-api.v127Decode JSON strings (escapes, UTF-8) into an owned buffer and compare decoded tokens.
std.data.json.digitsnone (scalar)5Decimal digit helpers for JSON numbers.
std.data.json.docuseful-data.v119Whole-document JSON structure: document end, key iteration, key uniqueness.
std.data.json.tokenuseful-data.v113JSON number and literal tokens: integer, fraction and exponent ends, true/false/null.
std.data.json.utf8useful-data.v111UTF-8 validation for JSON text.
std.data.json.writeuseful-data.v216Write JSON: quoted strings, escapes and decimal numbers into a buffer.
std.data.tomluseful-data.v116TOML scanning: bare and quoted keys, values, comments, failures.
std.dbuseful-data.v118Database-access rules: descriptor matching, safe identifiers, transaction state machine.
std.emailuseful-data.v232Email address, header and envelope validation.
std.encodingnone (scalar)10Hex and Base64 digit encode and decode helpers.
std.encoding.base64owned-data-api.v13Base64 length and byte access for an owned buffer.
std.envenvironment-io.v17Read process environment entries: count, name, value.
std.env.policyowned-data-api.v112Validity rules for environment variable names and assignments.
std.export.policyuseful-data.v29Admission rules for export batches: sizes, target ids, queue depth, backoff.
std.formatuseful-data.v214Build text in a buffer: append str, usize, i64 and bool, with padding.
std.fsfilesystem-io.v322Typed Path, FileInfo and WriteOutcome over the fs.* effects: read, write, metadata, list, create, remove, atomic write.
std.httpuseful-data.v158HTTP/1.1 message parsing: status, headers, Content-Length, method and token validity.
std.ioowned-data-api.v113Reader and Writer cursors over byte buffers.
std.io.linesowned-data-api.v17Line-oriented reading over a Reader.
std.jobsuseful-data.v129Durable-job state machine: states, leases, claim, heartbeat, retry and dead-letter rules.
std.loguseful-data.v227Structured JSON log events with levels and guarded append.
std.log.redactuseful-data.v213Log redaction policy: protected field names and safe events.
std.memowned-data-api.v13Owned Box: new, get, into_inner.
std.metricsuseful-data.v244Counters, gauges, histogram observation, label and cardinality rules.
std.netuseful-data.v124Network value checks: ports, hosts, IPv4 classes (loopback, private, link-local), wait results.
std.numnone (scalar)15abs, sign, gcd, pow, isqrt, div_euclid, rem_euclid, digit_count, log2_floor, log10_floor.
std.num.overflownone (scalar)13Overflow detection plus wrapping and saturating add, sub, neg, mul.
std.pathuseful-data.v16Path text queries: absolute, segments, file name, parent, extension.
std.path.normalizeowned-data-api.v117Normalize a path (resolve . and ..) into an owned buffer.
std.path.valueowned-data-api.v116Owned Path value: validation, join, parent.
std.processprocess-io.v129Argv and Output records and run for subprocesses.
std.randomnone (scalar)4Deterministic seeded generator: next_seed, sample_below.
std.testnone (scalar)10Assertion helpers: equal_i64, equal_bool, failure bit sets.
std.test.bytesuseful-data.v28Byte assertions and snapshot comparison.
std.textuseful-text-consumer.v15Byte length, contains, equals, is_empty, starts_with over borrowed text.
std.timenone (scalar)8Millisecond and second arithmetic: deadlines, remaining and elapsed time.
std.tracinguseful-data.v242W3C traceparent and tracestate validation.
std.urlnone (scalar)5URL scheme and percent-encoding byte predicates.
std.webhookuseful-data.v223Webhook admission: replay window, signature shape, delivery, backoff and idempotency rules.

scalar packages work in any project. Other profiles gate what a project may contain, for example std.fs needs filesystem-io.v3 and std.process needs process-io.v1, and those also need the matching effect and a provider that grants it (Input and output).

Traps

  • Mutators thread the owner. Write let next = vec_push<i64>(values, x);; there is no in-place mutation.
  • Most std.* packages are rule and parsing helpers over byte slices and scalars, not high-level clients. std.http parses messages; it does not open connections. For network access use the compiler-owned net_* and https_* functions (Built-in functions).
  • Compiler-owned functions (string_len, byte_get, stdout_write, box_new) are not in the standard library. They are reserved names in every file.
  • A stable id is <package>.<name>, for example std.core.min.

Contract: Standard Library v1.