For the complete documentation index, see llms.txt. This page is also available as Markdown.

Package index

OSL ships its standard library as importable packages:

import "std:fs"

log fs.readFile("notes.txt")

An import adds a package value with the same name. For example, std:fs adds fs. Use the std: prefix in new code. The older osl/ spelling still works, but the compiler reports a migration warning.

How imports work

Form
Meaning

import "std:fs"

A standard-library package listed below

import "./helpers.osl"

A local OSL file, relative to the importing file

import "utils" or import "./utils"

Every .osl file directly inside a local directory

import "git.rotur.dev/me/tools"

A Git dependency installed by Opal

import "go:net/http"

A Go package

Directory imports sort files by name and do not recurse. Import or re-export child directories yourself.

Missing third-party Go dependencies are fetched automatically when you compile.

Module objects

The statement form merges another file's declarations into the current scope. Its top-level statements run once, where OSL first imports the file. The expression form returns its public API as an object instead:

object math = import("./math.osl")

log math.add(2, 3)
log math.square(4)

Without an export statement, a file exposes all of its declarations. Adding an export statement turns on an explicit public API for that file:

Consumers can import the full API, selected names, or a namespace:

Files in the same directory can share private declarations. Consumers in another directory see only exported declarations. Missing, duplicate, and conflicting exports are compile errors.

Here math.square and math.quadruple are callable from outside. import(...) works with local .osl files whose path is a string literal.

Returned objects

Some packages give you an object to keep working with. For example, db.open() returns a database handle, and you call further methods on that:

Each package page lists handle methods in a separate section.

The standard library at a glance

Web & networking

Package
Description

HTTP server / web framework (routing, middleware, contexts).

WebSocket client and server.

Bot framework for OriginChats servers.

HTTP client methods including get, post, and put.

Low-level TCP/UDP sockets and DNS lookups.

URL parsing, building and query-string handling.

FTP file transfers.

SSH connections, remote commands and SCP.

S3-compatible object storage client.

Web Push notifications (VAPID).

Data & serialization

Package
Description

JSON parsing and encoding.

YAML parsing and encoding.

Composable validation and normalization schemas.

CSV parsing plus a small dataframe-style toolkit.

XML parsing and querying.

Lightweight {{ }} templating with HTML escaping.

Markdown to HTML (CommonMark + GFM via goldmark).

MIME-type lookup and parsing.

Text/line/word diffing.

Databases & storage

Package
Description

Embedded SQLite - SQL plus a document/collection API.

Simple persistent key-value storage.

In-memory LRU cache with TTLs.

Environment variables and .env files.

Filesystem & system

Package
Description

Files, directories and path utilities.

Runtime memory counters, heap snapshots, and live pprof diagnostics.

System info, environment, and running shell commands.

Spawn, manage and signal processes.

ZIP / TAR / GZIP compression.

Crypto & security

Package
Description

Hashing, HMAC, AES, password hashing, file encryption, random.

JSON Web Token signing and verification.

Text, math & time

Package
Description

Emoji detection, extraction, replacement, flags, and skin tones.

Regular expressions plus validators and text helpers.

Semantic-version parsing and comparison.

Maths, statistics and number theory.

Seedable pseudo-random numbers.

Dates, durations and time zones.

Cron-style job scheduling.

Bounded retries with exponential backoff and jitter.

Terminal & logging

Package
Description

Terminal UI: colours, boxes, tables, prompts, menus, charts.

Levelled, colourful logging.

Desktop notifications.

Media & documents

Package
Description

Load, transform and save images.

QR codes and barcodes.

Generate PDF documents.

In-memory pixel canvas.

Build colour values (used by image-producing packages).

Audio playback.

Graphics & windowing

Package
Description

GLSL and OSL-style shader transpilation and rendering to images and windows.

Native windowing, input, 2D drawing, collision helpers, shaders, and textures.

Open a window and draw to it (the originOS graphics model).

Install native window controls.

Scripting & concurrency

Package
Description

Assertions and the osl test workflow.

Run sandboxed JavaScript with hard resource limits.

Embed and run Lua scripts.

Background threads, parallel workers, racing, and message channels.

Named locks, scoped locking, one-time execution, and wait groups.

Utilities & data structures

Package
Description

Box2D-compatible rigid-body worlds, bodies, and fixtures.

An ordered key-value map type.

A set type.

Optional values (some/none).

Success/error result values.

Low-level pointer operations.

More

Package
Description

Compose and send email (SMTP).

Create and parse .torrent files.

To read a package's source directly from the CLI:

Last updated