Libraries
Sigil includes a collection of libraries for building real applications. This overview highlights the most useful ones.
Core Language
These libraries form the foundation of Sigil and are available in every program.
(sigil core)
Essential utilities that extend R7RS: list operations, association lists, string helpers, and common patterns. This module is automatically imported everywhere.
(filter-map (lambda (x) (and (> x 0) (* x 2))) '(-1 2 -3 4))
; => (4 8)
(assoc-ref 'name '((name . "Alice") (age . 30)))
; => "Alice"(sigil struct)
Define fixed-slot, opaque struct types with keyword construction and default values (the deftype role; for open, dict-backed typed data see (sigil record)).
(import (sigil struct))
(define-struct point (x) (y default: 0))
(define p (point x: 10 y: 20))
(point-x p) ; => 10(sigil record)
Define dict-backed typed values (the defrecord role): open, extensible, immutable records with unique type identity and single inheritance. Every dict operation works on a record.
(import (sigil record))
(define-record buffer (name))
(define-record editor-buffer include: buffer (text default: ""))
(define e (editor-buffer name: "*scratch*"))
(buffer? e) ; => #t (inherited)
(dict-ref e name:) ; => "*scratch*" (it IS a dict)
(editor-buffer e text: "hi") ; immutable typed update(sigil method)
Open dispatch (multimethods) over records, structs, or core values with one primitive: parent-chain inheritance, a default: catch-all, custom dispatch functions, and cached dispatch safe for live redefinition.
(import (sigil record) (sigil method))
(define-multi describe)
(define-method describe (b buffer) (list 'buffer (buffer-name b)))
(define-method describe (x default:) (list 'value x))
(describe (editor-buffer name: "*e*")) ; => (buffer "*e*")(sigil match)
Pattern matching for destructuring and control flow.
(import (sigil match))
(match '(1 2 3)
((a b c) (+ a b c)) ; => 6
(_ 'no-match))Data Formats
(sigil json)
Parse and generate JSON with hash-table literals.
(import (sigil json))
(define data #{ name: "Sigil" version: "0.1.0" })
(json-encode data)
; => "{\"name\":\"Sigil\",\"version\":\"0.1.0\"}"
(json-decode "{\"x\": 10}")
; => #{ x: 10 }(sigil yaml)
Parse and generate YAML, with block and flow styles, anchors and aliases, and multi-document streams.
(import (sigil yaml))
(define data (yaml-read "name: sigil\nversion: 0.7.0"))
(yaml-write data)(sigil markdown)
Parse Markdown to an AST for processing or rendering.
(import (sigil markdown))
(define doc (markdown-parse "# Hello\n\nSome *text*."))(sigil sxml)
Work with XML/HTML as S-expressions.
(import (sigil sxml))
(sxml->string
'(html (head (title "Hello"))
(body (p "Welcome!"))))(sigil org)
Parse Org Mode documents into SXML, ready to transform or render however you like.
(import (sigil org))
(org->sxml "#+TITLE: Notes\n\n* Tasks\n\nWrite the docs.")Networking
(sigil http)
HTTP client and server with a simple, functional API.
(import (sigil http))
;; Client
(define response (http-get "https://example.com/api"))
(http-response-body response)
;; Server
(define (handler req)
(http-response HTTP-OK "Hello, World!"))
(http-serve 8080 handler)(sigil socket)
Low-level TCP and UDP networking.
(import (sigil socket))
(define sock (tcp-connect "example.com" 80))
(socket-send sock "GET / HTTP/1.0\r\n\r\n")
(socket-recv sock 1024)(sigil websocket)
WebSocket client and server support.
(import (sigil websocket))
(websocket-connect "wss://echo.websocket.org"
(lambda (ws)
(websocket-send ws "Hello!")
(display (websocket-recv ws))))(sigil tls)
Secure TCP connections over TLS. Certificates are verified against your system's trust store by default, so you don't have to wire that up yourself.
(import (sigil tls))
(define conn (tls-connect "example.com" 443))
(tls-write conn "GET / HTTP/1.0\r\n\r\n")
(tls-read conn 1024)(sigil irc)
Talk to IRC networks. It handles the protocol so you can focus on your bot or client: joining channels, sending messages, and reacting to events.
(sigil xmpp)
An XMPP client with STARTTLS and SASL authentication for chat and messaging, including full JID parsing.
Web
(sigil web)
A framework for building interactive web apps where the server stays in charge. You render views as SXML, push live updates to the browser over Server-Sent Events, and wire up interactions with declarative data-sg-* attributes, so there's no hand-written client JavaScript to maintain. Routing, middleware, static files, and cookies come built in.
(import (sigil web routes))
(define app
(router
(route GET "/" home-handler)
(route GET "/users/:id" user-handler)
(route POST "/api/login" login-handler)))(sigil browser)
The other side of the browser story: Sigil compiled to WebAssembly, running client-side. This package bridges the core browser APIs (async scheduling, IndexedDB, and local storage), and the companion sigil-wasm-* libraries add the DOM, Canvas2D, WebGL, and networking bindings.
(sigil web client)
A react-like rendering layer for browser apps compiled to WebAssembly. You describe views as SXML and mount them into a DOM root, then re-render in place as your state changes. It builds on the WASM DOM bridge so your application code never touches the low-level backend, and it stays independent of the server-side (sigil web) framework.
(import (sigil web client))
(define root (web-client-root "#app"))
(web-client-mount root (lambda () `(div "Hello, world!")))
(web-client-update root (lambda () `(div "Updated!")))Security
(sigil crypto)
Cryptographic building blocks: hashing, HMACs, key derivation, ECDSA and ECDH, AES-GCM, and secure random bytes. It's the foundation the TLS library is built on.
(import (sigil crypto))
(sha256 "hello") ; => "2cf24dba5fb0a30e..."
(base64-encode "hello") ; => "aGVsbG8="(sigil jwt)
Create and verify JSON Web Tokens, the tokens behind most modern API authentication.
(import (sigil jwt))
(define token (jwt-encode '((sub . "user-123")) "my-secret"))
(jwt-decode token "my-secret") ; => claims dict, or #f if invalid(sigil oauth)
An OAuth 2.0 client for signing users in through providers like Google and GitHub. It handles the authorization redirect and the code-for-token exchange for you.
System
(sigil io)
File I/O beyond R7RS: read entire files, write strings, file metadata.
(import (sigil io))
(write-file "output.txt" "Hello, file!")
(read-file "output.txt") ; => "Hello, file!"(sigil fs)
Filesystem operations: directories, paths, globbing.
(import (sigil fs))
(directory-list ".")
(glob "src/**/*.sgl")
(file-exists? "config.json")(sigil process)
Spawn and manage external processes.
(import (sigil process))
(define result (run "ls" "-la"))
(process-output result)(sigil path)
Path manipulation that works across platforms.
(import (sigil path))
(path-join "src" "lib" "main.sgl") ; => "src/lib/main.sgl"
(path-extname "file.tar.gz") ; => ".gz"
(path-dirname "/home/user/file") ; => "/home/user"Concurrency
(sigil async)
Cooperative multitasking with lightweight tasks.
(import (sigil async))
(with-async
(go (begin
(display "Task A\n")
(sleep 0.1)
(display "Task A done\n")))
(go (begin
(display "Task B\n")
(sleep 0.05)
(display "Task B done\n"))))(sigil channels)
CSP-style channels for communicating between tasks.
(import (sigil async)
(sigil channels))
(with-async
(define ch (make-channel))
(go (channel-send ch "hello"))
(display (channel-recv ch))) ; => "hello"Database
(sigil sqlite)
SQLite database access.
(import (sigil sqlite))
(define db (sqlite-open "app.db"))
(sqlite-exec db "CREATE TABLE users (id INTEGER, name TEXT)")
(sqlite-exec db "INSERT INTO users VALUES (1, 'Alice')")
(sqlite-query db "SELECT * FROM users")Text Processing
(sigil string)
String utilities beyond R7RS.
(import (sigil string))
(string-split "a,b,c" ",") ; => ("a" "b" "c")
(string-join '("a" "b" "c") "-") ; => "a-b-c"
(string-trim " hello ") ; => "hello"(sigil regex)
Regular expressions in the RE2 / Go syntax. One match or search takes time linear in the input for every pattern, so a pattern like (a*)*b cannot hang a script the way it can with a backtracking engine. Positions are character indexes that work with substring. Also exported from the shell prelude.
(import (sigil regex))
(regex-match? "^[0-9a-f]{64}$" digest) ; whole string
(match-group (regex-search "v(\\d+)" "tag v12") 1) ; => "12"
(regex-replace-all "(\\w+)@(\\w+)" "me@host" "$2/$1") ; => "host/me"
(regex-split "\\s*,\\s*" "a , b,c") ; => ("a" "b" "c")(sigil ansi)
Terminal colors and formatting.
(import (sigil ansi))
(display (ansi-bold (ansi-red "Error: ")))
(display "Something went wrong\n")Command-Line Tools
(sigil args)
Parse command-line arguments with flags and subcommands.
(import (sigil args))
(define parser
(args-parser
(flag 'verbose "-v" "--verbose" "Enable verbose output")
(option 'output "-o" "--output" "Output file" default: "out.txt")))
(define opts (args-parse parser (command-line)))(sigil tui)
Build full-screen terminal interfaces with a render-and-update model, layout helpers, and mouse tracking. If you've enjoyed tools like htop or lazygit, this is how you write your own.
Development
(sigil test)
Testing framework with assertions and test suites.
(import (sigil test))
(test-group "math"
(test "addition" (assert-equal (+ 1 2) 3))
(test "multiplication" (assert-equal (* 3 4) 12)))
(run-tests)(sigil repl)
Embed a REPL in your application for debugging.
(sigil nrepl)
Run a network REPL so your editor can connect and evaluate code in a live program. Point Emacs or VS Code at the port and start hacking.
(import (sigil nrepl))
(define server (nrepl-start 7888))R7RS Compatibility
Sigil includes the standard R7RS libraries:
(scheme base)- Core language(scheme write)- Output procedures(scheme read)- Input procedures(scheme file)- File ports(scheme char)- Character operations(scheme cxr)- Extended car/cdr(scheme lazy)- Delayed evaluation(scheme case-lambda)- Multi-arity procedures(scheme process-context)- Environment access
All libraries
Beyond the libraries that ship with Sigil, the Sigil project publishes 59 more, each from its own repository. You add one to a project as a dependency in its package.sgl. A name with an arrow links to the library's repository, where its README is the documentation.
Ships with Sigil
sigil-stdlibThe standard librarysigil-argsCommand-line argument parsingsigil-testWriting testssigil-helpLooking up and searching API documentationsigil-formatFormatting Sigil codesigil-gitGit operationssigil-replAn interactive REPL to embedsigil-browserBrowser APIs for Sigil appssigil-wasm-domThe browser DOM from WASMsigil-wasm-netBrowser networking from WASMsigil-wasm-canvas2dThe browser's 2D canvas from WASMsigil-wasm-glWebGL2 from WASM
Web and networking
sigil-httpHTTP client and serversigil-webWeb application framework: routing, middleware, static files, cookiessigil-sxmlSXML to HTML and XMLsigil-cssStylesheets written as s-expressionssigil-web-client(repository on Codeberg)Browser UI framework for Sigil apps compiled to WASMsigil-web-styles(repository on Codeberg)Design system and themes for web appssigil-websocketWebSocket client and server, with TLSsigil-tls(repository on Codeberg)TLS connections, built on mbedTLSsigil-oauth(repository on Codeberg)OAuth 2.0 clientsigil-jwt(repository on Codeberg)JSON Web Tokenssigil-noise(repository on Codeberg)Noise XX encrypted sessions over any transportsigil-irc(repository on Codeberg)IRC client and protocolsigil-xmpp(repository on Codeberg)XMPP client with STARTTLS and SASL
Data and storage
sigil-jsonJSON parsing and generationsigil-yaml(repository on Codeberg)YAML parsing and serializationsigil-wire(repository on Codeberg)Typed binary encoding for Sigil valuessigil-sqliteSQLite database bindingssigil-peg(repository on Codeberg)Parsing expression grammarssigil-transducers(repository on Codeberg)Composable transducerssigil-r7rs(repository on Codeberg)R7RS-small compatibility: the (scheme ...) librariessigil-rss(repository on Codeberg)RSS and Atom feed parsingsigil-ledger(repository on Codeberg)Ledger and hledger journal files
Documents and publishing
sigil-markdownMarkdown and front matter parsersigil-org(repository on Codeberg)Org Mode parser that produces SXMLsigil-doc(repository on Codeberg)A programmable document language
Systems and terminals
sigil-cryptoHashes, HMAC, signatures, ciphers, key exchange and random bytessigil-ffi(repository on Codeberg)Calling C libraries at run timesigil-log(repository on Codeberg)Structured loggingsigil-later(repository on Codeberg)Scheduled tasks with cron expressionssigil-system(repository on Codeberg)Files, processes and terminals behind permission grantssigil-tuiTerminal user interfacessigil-vt(repository on Codeberg)A VT and ANSI terminal emulator core
Graphics and audio
sigil-graphics2D and 3D graphics, images and fontssigil-desktopWindows, input and the frame clock, over GLFWsigil-wm(repository on Codeberg)Wayland window managers, on wlrootssigil-geometry(repository on Codeberg)3D math: vectors, matrices, quaternions, cameras, rayssigil-image(repository on Codeberg)Image decoding and PNG encodingsigil-cairo(repository on Codeberg)Cairo 2D graphics bindingssigil-freetype(repository on Codeberg)FreeType font loadingsigil-harfbuzz(repository on Codeberg)HarfBuzz text shapingsigil-raylib(repository on Codeberg)Raylib game development bindingssigil-audioAudio playback and streamingsigil-dsp(repository on Codeberg)Oscillators, filters, effects and envelopes, from SoundPipemotif(repository on Codeberg)Music composition: describe tracks in a DSL, render them to WAV
Developer tools
sigil-lsp(repository on Codeberg)Language Server Protocol serverssigil-nrepl(repository on Codeberg)A network REPL serversigil-mcpModel Context Protocol clients and servers
Service clients
sigil-forgejo(repository on Codeberg)Forgejo and Codeberg APIsigil-caldav(repository on Codeberg)CalDAV calendarssigil-jmap(repository on Codeberg)JMAP emailsigil-discourse(repository on Codeberg)Discourse forums APIsigil-postmark(repository on Codeberg)Postmark email APIsigil-ses(repository on Codeberg)Amazon SES email APIsigil-cloudflare(repository on Codeberg)Cloudflare R2 object storagesigil-lemonsqueezy(repository on Codeberg)Lemon Squeezy store APIsigil-telegram(repository on Codeberg)Telegram Bot APIsigil-twitch(repository on Codeberg)Twitch Helix APIsigil-youtube(repository on Codeberg)YouTube Data APIsigil-wise(repository on Codeberg)Wise payments API