toml

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 12 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

📑 toml — TOML for Starlark

Go Reference codecov binary footprint

Decode and encode TOML from Starlark, built on BurntSushi/toml.

Both directions are hardened: nesting depth is bounded before the recursive codec runs (a deeply nested document would otherwise overflow the stack — a fatal error recover() cannot catch); decode also bounds input size and node count; the caps are host-only (a script cannot widen them); panics become errors; and TOML's native date/time values are surfaced as strings.

Overview

starpkg modules give Starlark scripts support for necessary local operations plus simple abstractions over common online services, for ease of use. toml is a local capability: it is a pure in-process codec — no network, no filesystem, no host services — turning TOML text into Starlark values and back.

  • decode(text) — parse a TOML document (string or bytes) into Starlark values (a dict).
  • encode(value) — serialize a dict to TOML text.
  • Hardened both ways — nesting depth bounded before the recursive codec runs (decode caps the text's bracket-opener count; encode walks the value), plus bounded input size and node count on decode; host-only caps; panics recovered into errors; date/time surfaced as strings; deterministic key order.

For the complete per-builtin reference — signatures, parameters, returns, errors, examples — and the configuration accessors, see docs/API.md.

Installation

go get github.com/starpkg/toml

Quickstart

load("toml", "decode", "encode")

doc = decode("""
name = "Ada"
langs = ["go", "python"]

[nested]
k = "v"
""")
doc["name"]            # => "Ada"
doc["langs"][0]        # => "go"
doc["nested"]["k"]     # => "v"

encode({"a": 1, "b": [1, 2]})   # => "a = 1\nb = [1, 2]\n"

Starlark API at a glance

Top-level builtins (load("toml", …)):

  • decode(text) — parse a TOML document (string or bytes) into a dict.
  • encode(value) — serialize a dict to TOML text (the top-level value must be a dict, since TOML documents are tables).

See docs/API.md for the full signatures, decoded value types, return values, errors, and examples of both builtins.

Configuration

The codec caps (max_depth, used by both decode and encode; max_nodes and max_input_bytes, used by decode) are host-only — they are DoS limits the module enforces against untrusted scripts, so each has a read-only get_<key> but no set_<key>, and a script cannot raise it. Configure them host-side via the TOML_* environment variables. See the Configuration section of docs/API.md for the full option table, defaults, and accessors.

License

MIT

Documentation

Overview

Package toml provides a Starlark module for decoding and encoding TOML.

Both directions are hardened against untrusted script input. A deeply nested document overflows the goroutine stack — a Go fatal error that recover() cannot catch — so before the recursive codec runs, decode caps the number of bracket openers in the text (a sound upper bound on parser recursion that needs no string lexing and so cannot be bypassed) and encode walks the value's depth. Decode additionally bounds input size and enforces the exact max_depth / node count on the parsed tree (capwalk); both codec calls recover ordinary panics into errors. The depth / node / input-size caps are host-only (no script setter), so a script cannot widen them. TOML's native date/time values are surfaced as strings (RFC 3339 for full timestamps), never as surprise opaque values.

Index

Constants

View Source
const ModuleName = "toml"

ModuleName is the name used in Starlark's load() for this module.

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module wraps a ConfigurableModule with TOML functions.

func NewModule

func NewModule() *Module

NewModule creates a new Module with default configuration.

func (*Module) LoadModule

func (m *Module) LoadModule() starlet.ModuleLoader

LoadModule returns the Starlark module loader.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址