Every public name, in brief. All are importable from the top-level package:
from ovos_spec_tools import expand, LocaleResources, render, closest_lang # etc.For the why and the worked examples, see the chapter each section links to.
Expansion — chapter 2
Expand a sentence template to its sample set. vocabularies is a
name -> list[str] dict, needed only if the template uses <name> references.
Raises MalformedTemplate.
ValueError subclass — a template violates OVOS-INTENT-1 §3.6.
Locale resources — chapter 3
LocaleResources(skill_locale, core_locale=None, user_locale=None, lang_resolver=None, max_language_distance=10)
Loads a skill's locale resource files. The three *_locale arguments are paths
to locale/ directories, in ascending override precedence. lang_resolver is
a (target, available, max_distance) -> str | None callable (default
closest_lang); max_language_distance caps the smart fallback (0 disables
it).
Methods — each takes a resource base name and a BCP-47 lang:
| Method | Returns |
|---|---|
load_intent(name, lang) |
expanded sample set, slots intact |
load_entity(name, lang) |
expanded value set |
load_vocabulary(name, lang) |
expanded phrase set |
load_blacklist(name, lang) |
expanded phrase set |
load_dialog(name, lang) |
raw phrase strings (not expanded) |
load_prompt(name, lang) |
the whole .prompt file, as one string |
vocabularies(lang) |
name -> templates for every .voc |
entities(lang) |
name -> values for every .entity |
A missing resource raises FileNotFoundError; a malformed one raises
MalformedResource.
Apply the OVOS-INTENT-2 §3 common reader to one file: UTF-8, BOM discarded,
LF/CRLF accepted, lines stripped, blank and #-comment lines dropped.
Read a .prompt whole and verbatim — UTF-8, BOM discarded, no line filtering.
ValueError subclass — a resource file or layout violates OVOS-INTENT-2
(empty file, duplicate (role, base name), a slot in a slot-free role).
Dialog — chapter 4
Render one phrase from an explicit list. slots fills {name} slots;
vocabularies resolves <name> references; rng is any object with a
choice method (for reproducible output). Raises UnfilledSlot, or
ValueError if phrases is empty.
A stateful, multilingual renderer for the dialog name, backed by a
LocaleResources. slots are default slot values reused on every call.
render(lang, slots=None) -> str— render one phrase inlang. Avoids repeating the previous phrase (per language). Slot precedence: per-call, then default, then a random.entityvalue, thenUnfilledSlot.
ValueError subclass — a chosen phrase has a slot with no value.
Prompts — chapter 4
Render a .prompt string. The whole text is the prompt; a {name} is
substituted only when it is a well-formed name, slots supplies a value, and
it is not inside a ``` fenced code block. An unfilled slot, and any
other {/`}`, is left literal. Never raises for an unfilled slot.
A stateful, multilingual renderer for the prompt name, backed by a
LocaleResources. slots are default values reused on every call.
render(lang, slots=None) -> str— render the prompt inlang; a per-call value overrides a default. RaisesFileNotFoundErrorif the prompt is missing forlang,MalformedResourceif the file is empty.
Language matching — chapter 5
Normalize a BCP-47 tag (underscores, case, canonical forms).
Distance between two tags: 0 is identical, >= 10 is not a usable match. A
bare tag is measured from its norm region.
The entry of available with the smallest lang_distance, if it is below
max_distance (or exact). Returns the original string, or None.
Bus messages — chapter 6
The OVOS-MSG-1 envelope: exactly three top-level fields — msg_type
(the wire field type), data, context. The constructor rejects
malformed input as MalformedMessage. data and context default to
empty dicts and are stored by reference.
m.forward(msg_type, data=None) -> Message— same context, new type/data; the forwarder does not become the newsource.m.reply(msg_type, data=None, context=None) -> Message— copies context, overlays the optionalcontext, swapssourceanddestination. Other context keys (includingsession) pass through unchanged.m.response(data=None, context=None) -> Message— sugar forreply(msg_type + ".response", ...).
All three preserve the runtime class — subclasses get back instances of their own subclass.
m.serialize() -> str— single UTF-8 JSON object per OVOS-MSG-1 §6; recursively converts nested objects exposing a.serialize()method (e.g.Session).m.as_dict -> dict(property) — JSON-decoded envelope, equivalent tojson.loads(m.serialize()). Nested.serialize()-walking carriers are converted the same way they would be on the wire.Message.deserialize(payload) -> Message— parse a JSON string, bytes, or already-parsed dict. Rejects unknown top-level keys, missingtype, wrong value types, NaN/Infinity asMalformedMessage.
ValueError subclass raised by the constructor and deserialize when a
payload violates OVOS-MSG-1 §2 / §6 / §7.
The reserved "default" value (OVOS-MSG-1 §4.1) — the Message
originates from the device itself. An absent session on a Message is
equivalent for every policy decision.
Linting — chapter 7
Validate every resource file under a locale (or single-language) directory.
spec_version (0, 1, or 2) flags features newer than that target — see
chapter 7.
A dataclass with severity ("error" / "warning"), path, and message.
str(finding) formats it as one line.
CLI wrapper over lint_locale. ovos-spec-lint <path> [--strict] [--spec-version {0,1,2}]; exit code is non-zero on errors (with --strict,
on warnings too).
The installed package version string.