loom.etl.schema¶
Schema, contracts, and table-reference primitives for ETL.
- loom.etl.schema.resolve_schema(contract)[source]¶
Convert a schema contract to a
tuple[ColumnSchema, ...].- Parameters:
contract (tuple[ColumnSchema, ...] | type[Any]) – Either a
tuple[ColumnSchema, ...](returned as-is) or an annotated class whose fields map to column schemas.- Returns:
Tuple of
ColumnSchemaentries.- Raises:
TypeError – If contract is not a supported schema contract form.
- Return type:
tuple[ColumnSchema, …]
- loom.etl.schema.resolve_json_type(contract)[source]¶
Convert a JSON column contract to a
LoomType.- Parameters:
contract (Any) – A
LoomType(returned as-is), an annotated class (converted toStructType), or alist[X]generic alias (converted toListType).- Returns:
LoomTypefor use with Polarsstr.json_decodeor Sparkfrom_json.- Raises:
TypeError – If contract cannot be converted to a LoomType.
- Return type:
LoomDtype | ListType | ArrayType | StructType | DecimalType | DatetimeType | DurationType | CategoricalType | EnumType
- class loom.etl.schema.ColumnSchema(name, dtype, nullable=True)[source]¶
Bases:
objectBackend-agnostic definition of a single table column.
Used by
TableDiscoveryto describe table schemas and by backend writers to align frames before writing.- Parameters:
name (str) – Column name.
dtype (LoomDtype | ListType | ArrayType | StructType | DecimalType | DatetimeType | DurationType | CategoricalType | EnumType) – Column type — any
LoomType. UseLoomDtypefor simple scalars; use the structural classes (ListType,StructType,DatetimeType, etc.) for complex or parametrised columns.nullable (bool) – Whether the column accepts null values. Defaults to
True.
Example:
schema = ( ColumnSchema("order_id", LoomDtype.INT64, nullable=False), ColumnSchema("amount", DecimalType(precision=18, scale=4)), ColumnSchema("tags", ListType(inner=LoomDtype.UTF8)), ColumnSchema("address", StructType(fields=( StructField("street", LoomDtype.UTF8), StructField("zip", LoomDtype.UTF8), ))), )
- class loom.etl.schema.LoomDtype(value)[source]¶
Bases:
StrEnumCanonical data types understood by loom’s schema system.
Values match Polars naming conventions to minimise translation friction in the Polars backend, while remaining backend-agnostic at the protocol level.
For complex / parametrised types use the dedicated structural classes (
ListType,ArrayType,StructType,DecimalType,DatetimeType,DurationType,CategoricalType,EnumType). The enum membersLIST,STRUCT, etc. are kept for coarse (unparameterised) schema declarations; they accept any inner type during validation.
- exception loom.etl.schema.SchemaNotFoundError[source]¶
Bases:
ExceptionRaised when a write is attempted but no schema is registered for the table.
Register the schema via
update_schema()before the first write, or use a backend that creates the table explicitly (for example withOVERWRITEon first write).
- exception loom.etl.schema.SchemaError[source]¶
Bases:
ExceptionRaised when a frame is incompatible with the registered table schema.
- class loom.etl.schema.ListType(inner)[source]¶
Bases:
objectHomogeneous list column —
List[inner].- Parameters:
inner (LoomDtype | ListType | ArrayType | StructType | DecimalType | DatetimeType | DurationType | CategoricalType | EnumType) – Element type. May itself be a
StructType,ListType, or any otherLoomType.
Example:
ListType(inner=LoomDtype.UTF8) ListType(inner=StructType(fields=(StructField("x", LoomDtype.INT64),)))
- class loom.etl.schema.ArrayType(inner, width)[source]¶
Bases:
objectFixed-width array column —
Array[inner, width].- Parameters:
inner (LoomDtype | ListType | ArrayType | StructType | DecimalType | DatetimeType | DurationType | CategoricalType | EnumType) – Element type.
width (int) – Fixed number of elements per row.
Example:
ArrayType(inner=LoomDtype.FLOAT64, width=3)
- class loom.etl.schema.StructType(fields)[source]¶
Bases:
objectRecord / struct column with named fields.
- Parameters:
fields (tuple[StructField, ...]) – Ordered tuple of
StructFielddefinitions.
Example:
StructType(fields=( StructField("lat", LoomDtype.FLOAT64), StructField("lon", LoomDtype.FLOAT64), ))
- class loom.etl.schema.StructField(name, dtype, nullable=True)[source]¶
Bases:
objectA single named field within a
StructType.- Parameters:
name (str) – Field name.
dtype (LoomDtype | ListType | ArrayType | StructType | DecimalType | DatetimeType | DurationType | CategoricalType | EnumType) – Field type — any
LoomType.nullable (bool) – Whether the field accepts nulls. Defaults to
True.
- class loom.etl.schema.DecimalType(precision=None, scale=None)[source]¶
Bases:
objectFixed-precision decimal column.
- Parameters:
Example:
DecimalType(precision=18, scale=4)
- class loom.etl.schema.DatetimeType(time_unit='us', time_zone=None)[source]¶
Bases:
objectDatetime column with explicit time unit and optional timezone.
- Parameters:
Example:
DatetimeType("us", "UTC") DatetimeType("ns") # naive, nanosecond precision
- class loom.etl.schema.DurationType(time_unit='us')[source]¶
Bases:
objectDuration (timedelta) column with explicit time unit.
- Parameters:
time_unit (str) –
"us"(microseconds, default),"ns", or"ms".
Example:
DurationType("ms")
- class loom.etl.schema.CategoricalType[source]¶
Bases:
objectDictionary-encoded categorical string column.
Example:
ColumnSchema("region", CategoricalType())
- class loom.etl.schema.EnumType(categories)[source]¶
Bases:
objectFixed-vocabulary enum column.
Example:
EnumType(categories=("low", "medium", "high"))
- class loom.etl.schema.TableRef(ref)[source]¶
Bases:
objectLogical table identifier used by the ETL declarative DSL.
- Parameters:
ref (str) – Dotted logical table reference (for example
"raw.orders").
- property c: _ColumnNamespace¶
Column namespace for bound references.