# Standard library

> Everything that ships with the compiler. Each package has a walkthrough and its full API, generated from its source.

This is the Markdown version of https://osl-lang.org/packages. Every page of the OSL docs has one: add .md to its path. https://osl-lang.org/llms.txt lists them all.

Import a package with `import "std:name"`. Nothing to install: every package here is part of the compiler.

### Web and networking

HTTP servers and clients, WebSockets, raw sockets and remote file systems.

- [serve](/packages/serve.md): Runs HTTP servers with routes, middleware, templates, static files and WebSocket endpoints.
- [ws](/packages/ws.md): Runs WebSocket servers and opens WebSocket client connections that exchange text, binary and JSON messages.
- [requests](/packages/requests.md): Sends HTTP requests and returns their responses, whole or as streams of lines and server-sent events.
- [url](/packages/url.md): Parses, builds, resolves and escapes URLs and query strings.
- [net](/packages/net.md): Opens TCP, Unix and UDP sockets and resolves host names; use std:requests for HTTP and std:url for URLs.
- [mime](/packages/mime.md): Looks up media types by file extension and parses and formats Content-Type values.
- [ftp](/packages/ftp.md): Connects to FTP servers to list, upload, download, rename and delete remote files and directories.
- [ssh](/packages/ssh.md): Connects to SSH servers with host-key verification to run commands, read, write and manage files over SFTP and forward ports, and manages SSH keys.
- [s3](/packages/s3.md): Uploads, downloads and deletes objects in Amazon S3 and S3-compatible storage such as R2 and MinIO, and signs presigned URLs.
- [webpush](/packages/webpush.md): Sends Web Push notifications to browser subscriptions, with VAPID keys, signing and RFC 8291 payload encryption.
- [email](/packages/email.md): Composes email messages with attachments and sends them through an SMTP server.
- [torrent](/packages/torrent.md): Creates, reads and writes BitTorrent metainfo (.torrent) files and magnet links, and downloads and seeds torrents as a BitTorrent client.

### Apps and graphics

Desktop interfaces, windows, games, 2D physics and GPU shaders.

- [ui](/packages/ui.md): Build interfaces from tags written in OSL, shown as live web pages by std:serve's app.UI and as native windows by std:window.
- [window](/packages/window.md): Open native windows that show std:ui interfaces, drawn with SDL2, with menus, dialogs, shortcuts and the clipboard.
- [layout](/packages/layout.md): Lay out std:ui tags in boxes without a screen: build nodes, measure them, find what sits at a point, and inspect and change a tree.
- [raylib](/packages/raylib.md): raylib windows with 2D and 3D drawing, keyboard and mouse input, textures, images, shaders and render textures, exchanging pixels with img.Image
- [raygui](/packages/raygui.md): Immediate-mode GUI controls for raylib windows: buttons, toggles, sliders, text fields, lists, dropdowns, color pickers, dialogs and styles
- [box2d](/packages/box2d.md): Box2D rigid-body physics: worlds of static, dynamic and kinematic bodies built from box, circle and polygon shapes
- [shader](/packages/shader.md): Transpile OSL-style shader code into GLSL for raylib, with example shaders
- [canvas](/packages/canvas.md): The built-in canvas pixel buffer is deprecated; see what it did and how to move the same code to std:img.
- [svg](/packages/svg.md): Render SVG documents into img.Image values, read their size and viewBox, and register fonts for SVG text

### Data and formats

Parse, validate, transform and write structured text.

- [json](/packages/json.md): Parse, stringify and stream JSON text.
- [schema](/packages/schema.md): Validate and normalise OSL values against composable schemas.
- [yaml](/packages/yaml.md): Parse and stringify YAML text.
- [csv](/packages/csv.md): Parse and write CSV text as arrays of objects or rows of cells.
- [xml](/packages/xml.md): Parse, query, edit and write XML documents.
- [md](/packages/md.md): Converts Markdown (with GitHub tables, task lists and strikethrough) to HTML and HTML back to Markdown.
- [template](/packages/template.md): Fills {{ }} templates from an object, with {{#if}}, {{#unless}} and {{#each}} blocks and optional HTML escaping.
- [diff](/packages/diff.md): Compare texts line by line, word by word or character by character and format the differences.
- [encodings/utf16](/packages/encodings-utf16.md): Measures, indexes, orders and case-maps strings like JavaScript does, counting UTF-16 code units with 1-based positions.

### Storage

Databases, key-value saves, caches and configuration.

- [db](/packages/db.md): SQLite databases with SQL queries and JSON document collections.
- [save](/packages/save.md): Persistent per-app storage of named text items under ~/.osl/apps.
- [cache](/packages/cache.md): In-memory key-value caches that evict the least recently used entry and expire entries after a time to live.
- [env](/packages/env.md): Read and set environment variables, and load, edit and save .env files.
- [mem](/packages/mem.md): Inspect the program's memory use, write pprof profiles and serve live profiling data.

### Files and the system

Files, processes, the terminal, logging and archives.

- [fs](/packages/fs.md): Read, write and manage files and directories, and work with path strings.
- [process](/packages/process.md): Run commands and manage processes, and read the current program's arguments, working directory and IDs.
- [sys](/packages/sys.md): Information about the operating system, machine and user, and opening URLs in the default app.
- [tui](/packages/tui.md): Builds terminal interfaces: colours and styles, boxes, tables and charts as strings, cursor control, prompts, key input and a redrawable screen buffer.
- [log](/packages/log.md): Levelled, timestamped console logging with a history of recent entries and progress output.
- [notify](/packages/notify.md): Show desktop notifications and alert dialogs on macOS, Linux and Windows.
- [zip](/packages/zip.md): Create, inspect and extract ZIP and tar archives, and gzip files and strings.

### Concurrency

Threads, channels, locks, events, retries and schedules.

- [thread](/packages/thread.md): Run functions on threads, wait for their results, and pass values between them over channels.
- [sync](/packages/sync.md): Lock values, one-time initialisation and wait groups for coordinating threads.
- [events](/packages/events.md): Named in-process events whose listeners can be added, removed and emitted from any thread.
- [retry](/packages/retry.md): Call a function again after it fails, waiting longer between attempts.
- [cron](/packages/cron.md): Run functions on five-field cron schedules from a background scheduler.

### Security

Hashing, encryption, signatures and tokens.

- [crypto](/packages/crypto.md): Hashes, HMACs, password hashing, authenticated encryption, Ed25519 signatures and secure random values.
- [jwt](/packages/jwt.md): Create and check HMAC-signed JSON Web Tokens (HS256, HS384, HS512).

### Text, numbers and time

Maths, randomness, dates, regular expressions, versions and emoji.

- [math](/packages/math.md): Math functions and constants beyond the built-ins: trigonometry, number theory, statistics and binary64 primitives.
- [random](/packages/random.md): Fast seedable pseudo-random numbers, items, shuffles and strings; use crypto for secrets.
- [date](/packages/date.md): Dates, times and durations: date.DateTime instants in UTC, time zones, arithmetic, formatting and parsing.
- [regex](/packages/regex.md): Regular expressions from strings (RE2 syntax), compiled patterns, and text validators and extractors built on them.
- [semver](/packages/semver.md): Parse, compare and range-match semantic versions such as "1.4.0-rc.1".
- [emoji](/packages/emoji.md): Finds, counts, extracts and removes emoji in text, counting flags, keycaps, skin tones and ZWJ sequences as one emoji each.
- [colors](/packages/colors.md): Parse CSS colors into OSL colors and convert, mix, lighten and darken them

### Media and documents

Images, photos' metadata, QR codes, PDFs and sound.

- [img](/packages/img.md): Create, draw on, filter, inspect, decode and encode images, with shapes, paths, gradients and text, every frame of animated GIF, PNG and WebP files, and ICC color profiles kept throughout
- [exif](/packages/exif.md): Read the EXIF orientation of JPEG, PNG, WebP and TIFF images and remove their EXIF metadata without re-encoding
- [qr](/packages/qr.md): Makes QR codes and Code 128, EAN-13, UPC-A and Code 39 barcodes as images, and reads them back.
- [pdf](/packages/pdf.md): Creates PDF documents with text, shapes, images, tables, bookmarks and watermarks, and merges and splits PDFs it wrote.
- [sound](/packages/sound.md): Play WAV, MP3, OGG Vorbis and QOA audio with per-sound volume, pitch, pan, pause and seeking

### Values and types

Results, options, sets, maps and pointers.

- [result](/packages/result.md): The result<T, E> type: the value of an operation that succeeded, or the error it failed with.
- [option](/packages/option.md): The option type: some(value) or none(), for an optional value whose absence must be told apart from null.
- [set](/packages/set.md): Keep a collection of unique values with fast membership tests, and combine sets with union, intersection and difference.
- [map](/packages/map.md): Look values up by key with map(), whose keys can be strings, numbers or booleans, and know when a typed map or an object fits better.
- [ptr](/packages/ptr.md): Shared mutable cells and low-level identity, address and memory-layout queries.

### Embedding and testing

Run JavaScript and Lua inside OSL, and test your code.

- [js](/packages/js.md): Run JavaScript in a sandboxed QuickJS runtime with a hard timeout, a memory cap and no access to the host.
- [lua](/packages/lua.md): Run Lua 5.1 code with gopher-lua, in one-off calls or in lua.State handles that keep globals, call Lua functions and expose OSL ones.
- [testing](/packages/testing.md): Assertions for OSL tests that throw an AssertionError naming what went wrong.

### Accounts and chat bots

Rotur accounts and originChats bots.

- [rotur](/packages/rotur.md): Client for the rotur.dev API: sign in, accounts, posts, groups, economy, signing and encryption, storage and realtime presence.
- [originchats](/packages/originchats.md): Bot framework for originChats servers: connect, react to messages and slash commands, and manage channels, threads and users.
