toml

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 10 Imported by: 0

README

📑 toml — TOML for Starlark

Go Reference codecov binary footprint

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

Decoding is hardened: input size, nesting depth, and total node count are bounded; 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 decode — bounded input size, nesting depth, and node count; 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 module's decode caps (max_depth, max_nodes, max_input_bytes) are configured via environment variables (TOML_*) or per-option get_<key> / set_<key> accessor builtins. 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.

Decoding is hardened: input size, nesting depth, and total node count are bounded (capwalk), and panics are recovered into errors. 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