Skip to content

Template

The YAML template model. Template.load reads a .crease.yml file; Template.model builds a Pydantic model from an entity's field declarations.

Template

Bases: BaseModel

load classmethod

load(path: str | Path) -> Template

Load a template from a .crease.yml file.

Parameters:

Name Type Description Default
path str | Path

Path to the YAML file.

required

Returns:

Type Description
Template

A validated Template instance.

save

save(path: str | Path) -> None

Write the template to a .crease.yml file.

model

model(entity: str) -> type[BaseModel]

Build a Pydantic model from an entity's field declarations.

Field types map as: string/email/uuid/url → str, integer → int, number → float, boolean → bool, datedatetime.date, datetimedatetime.datetime. Nullable fields are T | None with default None.

The generated model uses extra="ignore" so enriched / extra keys don't error. Pydantic's default coercion is permitted (e.g. an ISO-format date string projects into datetime.date) — truly incompatible inputs still raise, which is what callers want from "throw if the type is wrong."

Parameters:

Name Type Description Default
entity str

Name of the entity (must match Entity.name).

required

Returns:

Type Description
type[BaseModel]

A new Pydantic BaseModel subclass.

Raises:

Type Description
KeyError

If no entity with that name exists.

Entity

Bases: BaseModel

FieldSpec

Bases: BaseModel

A canonical field: name, type, source mapping, constraints.

Locate

Bases: BaseModel

Where (and how) to find an entity's data.

Anchor

Bases: BaseModel

Locate one field's value in anchored orientation.

HeaderAnchor

Bases: BaseModel

Locate the header row by scanning for a known label rather than a fixed index.

DataEnd

Bases: BaseModel

Enrich

Bases: BaseModel

Inject a field into extracted rows derived from the tab name.

Unpivot

Bases: BaseModel

Reshape wide-format data into long-format during extraction.