Skip to content

momoa.engines

source package momoa.engines

Engine protocol and registry for Momoa model compilation.

Classes

  • EngineResult Result of compiling a schema spec into model classes.

  • Serializable Anything that can serialize itself to a JSON-compatible dict.

  • ModelEngine Compiles a normalised schema spec into model classes.

Functions

  • resolve_engine Look up a registered engine by name, raising UnknownEngineError for unknown names.

source dataclass EngineResult(models: tuple[type, ...])

Result of compiling a schema spec into model classes.

Attributes

  • model : type The primary (root) model class.

source property EngineResult.model: type

The primary (root) model class.

source class Serializable()

Bases : Protocol

Anything that can serialize itself to a JSON-compatible dict.

Methods

  • serialize Return a JSON-compatible dict representation of this instance.

source method Serializable.serialize()dict[str, Any]

Return a JSON-compatible dict representation of this instance.

source class ModelEngine()

Bases : Protocol

Compiles a normalised schema spec into model classes.

Attributes

  • output_format : str 'statham', 'pydantic', 'dataclass', etc.

Methods

  • compile Returns models built from the spec. Pure: same input -> equivalent output.

  • context_labeller Returns a context_labeller for json_ref_dict.materialize, or None.

source property ModelEngine.output_format: str

'statham', 'pydantic', 'dataclass', etc.

source method ModelEngine.compile(spec: dict[str, Any], *, root_name: str | None = None)EngineResult

Returns models built from the spec. Pure: same input -> equivalent output.

source method ModelEngine.context_labeller()Callable[[str], tuple[str, Any]] | None

Returns a context_labeller for json_ref_dict.materialize, or None.

Engines that need schema nodes labelled during URI materialisation (e.g. to derive names for anonymous nested objects) return a callable here. Engines that work from plain schema dicts return None.

source resolve_engine(name: str)ModelEngine

Look up a registered engine by name, raising UnknownEngineError for unknown names.

Raises