Skip to content

Records⚓︎

records ⚓︎

Lightweight typed records produced from table schemas.

Schema records are created after table shape validation, field parsing, and source metadata collection. They behave like small dataclass-style objects without requiring schema classes to define __init__ methods.

Info

Output-model conversion happens after records are finalized. Use parse() when tests need these source-aware record objects.

TableRecord ⚓︎

Base record object created before optional model conversion.

Attributes:

Warning

Users normally subclass RowTable or ColumnTable rather than TableRecord directly.

table_source property ⚓︎

table_source: RecordSource

Return immutable source metadata for this parsed record.

Returns:

  • RecordSource

    RecordSource containing record and field cell locations.

Info

Source metadata remains available even when validation later raises an error, making custom diagnostics easier to build.

table_extras property ⚓︎

table_extras: Mapping[str, Any]

Return values preserved by schema policy.

Returns:

  • Mapping[str, Any]

    Read-only mapping of preserved inapplicable variant labels to values.

Warning

Extras exist only when the variant inapplicable-field policy is "preserve". Code should not depend on them for required domain fields.

_from_values classmethod ⚓︎

_from_values(
    values: dict[str, Any],
    *,
    source: RecordSource | None = None,
    extras: Mapping[str, Any] | None = None,
) -> TableRecord

Construct a schema record without invoking user initialization.

Parameters:

  • values (dict[str, Any]) –

    Parsed values keyed by schema attribute name.

  • source (RecordSource | None, default: None ) –

    Optional source metadata for the record.

  • extras (Mapping[str, Any] | None, default: None ) –

    Optional preserved extra values.

Returns:

Info

Schema classes declare fields as descriptors, so direct assignment through setattr attaches values consistently with normal attribute access.

source_for ⚓︎

source_for(field_name: str) -> Any

Return the original TableCell for one schema attribute.

Parameters:

  • field_name (str) –

    Python schema attribute name.

Returns:

  • Any

    Source-aware cell for the requested field.

Raises:

  • KeyError

    If no source cell exists for field_name.

Example

cell = record.source_for("email")
raise TableError.from_cell("Invalid email", cell)

as_dict ⚓︎

as_dict() -> dict[str, Any]

Return declared schema fields as a new dictionary.

Returns:

  • dict[str, Any]

    Mapping from schema attribute names to parsed values.

Info

Source metadata and extras are intentionally excluded so the result is suitable for output-model keyword arguments.

__repr__ ⚓︎

__repr__() -> str

Return a constructor-like representation of declared fields.

Returns:

  • str

    String containing the record type and parsed field values.

Info

The representation is meant for tests and debugging, not for round-tripping records.

__eq__ ⚓︎

__eq__(other: object) -> bool

Compare records by concrete type and declared field values.

Parameters:

  • other (object) –

    Object being compared to this record.

Returns:

  • bool

    True when both records have the same concrete schema type and

  • bool

    parsed field dictionary.

Warning

Source metadata and preserved extras do not participate in equality. They describe provenance rather than record identity.