Skip to content

Types

YadsType

Bases: ABC

Abstract base class for all yads data types.

All type definitions in yads inherit from this base class, providing a consistent interface for type representation and conversion across different target systems.

Source code in src/yads/types.py
68
69
70
71
72
73
74
75
76
77
class YadsType(ABC):
    """Abstract base class for all yads data types.

    All type definitions in yads inherit from this base class, providing
    a consistent interface for type representation and conversion across
    different target systems.
    """

    def __str__(self) -> str:
        return self.__class__.__name__.lower()

String dataclass

Bases: YadsType

Variable-length string type with optional maximum length constraint.

Represents text data. The length parameter specifies the maximum number of characters when applicable.

Parameters:

Name Type Description Default
length int | None

Maximum number of characters. If None, represents unlimited length.

None

Raises:

Type Description
TypeDefinitionError

If length is not a positive integer.

Source code in src/yads/types.py
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
@dataclass(frozen=True)
class String(YadsType):
    """Variable-length string type with optional maximum length constraint.

    Represents text data. The `length` parameter specifies the maximum number
    of characters when applicable.

    Args:
        length: Maximum number of characters. If None, represents unlimited length.

    Raises:
        TypeDefinitionError: If length is not a positive integer.
    """

    length: int | None = None

    def __post_init__(self):
        if self.length is not None and self.length <= 0:
            raise TypeDefinitionError(
                f"String 'length' must be a positive integer, not {self.length}."
            )

    def __str__(self) -> str:
        return _format_type_str("string", [("length", self.length)])

Integer dataclass

Bases: YadsType

Integer type with optional bit-width and signedness specification.

Represents whole numbers. Bit-width controls representable range; signed controls whether the integer is signed.

Parameters:

Name Type Description Default
bits int | None

Number of bits for the integer. Must be 8, 16, 32, or 64. If None, uses the default integer type for the target system.

None
signed bool

Whether the integer is signed. Defaults to True.

True

Raises:

Type Description
TypeDefinitionError

If bits is not one of the valid values or if signed is not a boolean.

Source code in src/yads/types.py
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
@dataclass(frozen=True)
class Integer(YadsType):
    """Integer type with optional bit-width and signedness specification.

    Represents whole numbers. Bit-width controls representable range; `signed`
    controls whether the integer is signed.

    Args:
        bits: Number of bits for the integer. Must be 8, 16, 32, or 64.
            If None, uses the default integer type for the target system.
        signed: Whether the integer is signed. Defaults to True.

    Raises:
        TypeDefinitionError: If `bits` is not one of the valid values or
            if `signed` is not a boolean.
    """

    bits: int | None = None
    signed: bool = True

    def __post_init__(self):
        if self.bits is not None and self.bits not in {8, 16, 32, 64}:
            raise TypeDefinitionError(
                f"Integer 'bits' must be one of 8, 16, 32, 64, not {self.bits}."
            )
        if not isinstance(self.signed, bool):  # pyright: ignore[reportUnnecessaryIsInstance]
            raise TypeDefinitionError("Integer 'signed' must be a boolean.")

    def __str__(self) -> str:
        # Only render 'signed' when it differs from the default (False)
        if self.bits is not None and self.signed is False:
            return f"integer(bits={self.bits}, signed=False)"
        if self.bits is not None:
            return f"integer(bits={self.bits})"
        if self.signed is False:
            return "integer(signed=False)"
        return "integer"

Float dataclass

Bases: YadsType

IEEE floating-point number type with optional precision specification.

Represents approximate numeric values with fractional components.

Parameters:

Name Type Description Default
bits int | None

Number of bits for the float. Must be 16, 32, or 64. 16-bit corresponds to half precision, 32-bit to single precision, and 64-bit to double precision. If None, uses the default float type for the target system.

None

Raises:

Type Description
TypeDefinitionError

If bits is not 16, 32, or 64.

Source code in src/yads/types.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@dataclass(frozen=True)
class Float(YadsType):
    """IEEE floating-point number type with optional precision specification.

    Represents approximate numeric values with fractional components.

    Args:
        bits: Number of bits for the float. Must be 16, 32, or 64.
              16-bit corresponds to half precision, 32-bit to single precision,
              and 64-bit to double precision. If None, uses the default float
              type for the target system.

    Raises:
        TypeDefinitionError: If bits is not 16, 32, or 64.
    """

    bits: int | None = None

    def __post_init__(self):
        if self.bits is not None and self.bits not in {16, 32, 64}:
            raise TypeDefinitionError(
                f"Float 'bits' must be one of 16, 32, or 64, not {self.bits}."
            )

    def __str__(self) -> str:
        return _format_type_str("float", [("bits", self.bits)])

Decimal dataclass

Bases: YadsType

Fixed-precision decimal type.

Parameters:

Name Type Description Default
precision int | None

Total number of digits (before and after decimal point).

None
scale int | None

Number of digits after the decimal point. Can be negative to indicate rounding to the left of the decimal point.

None
bits int | None

Decimal arithmetic/storage width. One of 128 or 256. Defaults to None (unspecified). Compatibility between bit width and precision is delegated to target converters.

None

Both precision and scale must be specified together, or both omitted for a default decimal type.

Raises:

Type Description
TypeDefinitionError

If only one of precision/scale is specified, or if values are invalid.

Source code in src/yads/types.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
@dataclass(frozen=True)
class Decimal(YadsType):
    """Fixed-precision decimal type.

    Args:
        precision: Total number of digits (before and after decimal point).
        scale: Number of digits after the decimal point. Can be negative to
            indicate rounding to the left of the decimal point.
        bits: Decimal arithmetic/storage width. One of `128` or `256`.
            Defaults to `None` (unspecified). Compatibility between bit width
            and precision is delegated to target converters.

    Both precision and scale must be specified together, or both omitted
    for a default decimal type.

    Raises:
        TypeDefinitionError: If only one of precision/scale is specified,
                           or if values are invalid.
    """

    precision: int | None = None
    scale: int | None = None
    bits: int | None = None

    def __post_init__(self):
        if (self.precision is None) != (self.scale is None):
            raise TypeDefinitionError(
                "Decimal type requires both 'precision' and 'scale', or neither."
            )
        if self.precision is not None and (
            not isinstance(self.precision, int) or self.precision <= 0  # pyright: ignore[reportUnnecessaryIsInstance]
        ):
            raise TypeDefinitionError(
                f"Decimal 'precision' must be a positive integer, not {self.precision}."
            )
        if self.scale is not None and (not isinstance(self.scale, int)):  # pyright: ignore[reportUnnecessaryIsInstance]
            raise TypeDefinitionError(
                f"Decimal 'scale' must be an integer, not {self.scale}."
            )
        if self.bits is not None and self.bits not in {128, 256}:
            raise TypeDefinitionError(
                f"Decimal 'bits' must be one of 128 or 256, not {self.bits}."
            )

    def __str__(self) -> str:
        if self.precision is not None and self.scale is not None:
            return _format_type_str(
                "decimal",
                [
                    ("precision", self.precision),
                    ("scale", self.scale),
                    ("bits", self.bits),
                ],
            )
        return _format_type_str("decimal", [("bits", self.bits)])

Boolean dataclass

Bases: YadsType

Boolean type representing true/false values.

Source code in src/yads/types.py
230
231
232
@dataclass(frozen=True)
class Boolean(YadsType):
    """Boolean type representing true/false values."""

Binary dataclass

Bases: YadsType

Binary data type for storing byte sequences.

Parameters:

Name Type Description Default
length int | None

Optional maximum number of bytes. If None, represents variable-length binary.

None

Raises:

Type Description
TypeDefinitionError

If length is provided and is not a positive integer.

Source code in src/yads/types.py
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
@dataclass(frozen=True)
class Binary(YadsType):
    """Binary data type for storing byte sequences.

    Args:
        length: Optional maximum number of bytes. If None, represents
            variable-length binary.

    Raises:
        TypeDefinitionError: If `length` is provided and is not a
            positive integer.
    """

    length: int | None = None

    def __post_init__(self):
        if self.length is not None and self.length <= 0:
            raise TypeDefinitionError(
                f"Binary 'length' must be a positive integer, not {self.length}."
            )

    def __str__(self) -> str:
        return _format_type_str("binary", [("length", self.length)])

Date dataclass

Bases: YadsType

Calendar date type representing year, month, and day.

Parameters:

Name Type Description Default
bits int | None

Storage width for logical date. One of 32 or 64. Defaults to 32.

None
Source code in src/yads/types.py
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
@dataclass(frozen=True)
class Date(YadsType):
    """Calendar date type representing year, month, and day.

    Args:
        bits: Storage width for logical date. One of `32` or `64`. Defaults
            to `32`.
    """

    bits: int | None = None

    def __post_init__(self):
        if self.bits is not None and self.bits not in {32, 64}:
            raise TypeDefinitionError(
                f"Date 'bits' must be one of 32 or 64, not {self.bits}."
            )

    def __str__(self) -> str:
        return _format_type_str("date", [("bits", self.bits)])

TimeUnit

Bases: str, Enum

Granularity for logical time and timestamps.

Order reflects increasing coarseness: ns < us < ms < s.

Source code in src/yads/types.py
281
282
283
284
285
286
287
288
289
290
class TimeUnit(str, Enum):
    """Granularity for logical time and timestamps.

    Order reflects increasing coarseness: ns < us < ms < s.
    """

    NS = "ns"
    US = "us"
    MS = "ms"
    S = "s"

Time dataclass

Bases: YadsType

Time-of-day type with fractional precision.

Represents a wall-clock time without a date component. Precision is expressed via a time unit granularity.

Parameters:

Name Type Description Default
unit TimeUnit | None

Smallest time unit for values. One of "s", "ms", "us", or "ns". Defaults to "ms".

MS
bits int | None

Storage width for logical time. One of 32 or 64. Defaults to None. Compatibility between bit width and unit is delegated to target converters.

None

Raises:

Type Description
TypeDefinitionError

If unit is not one of the supported values.

Source code in src/yads/types.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
@dataclass(frozen=True)
class Time(YadsType):
    """Time-of-day type with fractional precision.

    Represents a wall-clock time without a date component. Precision is expressed
    via a time unit granularity.

    Args:
        unit: Smallest time unit for values. One of `"s"`, `"ms"`, `"us"`,
            or `"ns"`. Defaults to `"ms"`.
        bits: Storage width for logical time. One of `32` or `64`.
            Defaults to `None`. Compatibility between bit width and unit
            is delegated to target converters.

    Raises:
        TypeDefinitionError: If `unit` is not one of the supported values.
    """

    unit: TimeUnit | None = TimeUnit.MS
    bits: int | None = None

    def __post_init__(self):
        if not isinstance(self.unit, TimeUnit):
            allowed = {u.value for u in TimeUnit}
            raise TypeDefinitionError(
                f"Time 'unit' must be one of {allowed}, not {self.unit}."
            )
        if self.bits is not None and self.bits not in {32, 64}:
            raise TypeDefinitionError(
                f"Time 'bits' must be one of 32 or 64, not {self.bits}."
            )

    def __str__(self) -> str:
        return _format_type_str(
            "time",
            [
                (
                    "unit",
                    self.unit.value if isinstance(self.unit, TimeUnit) else self.unit,
                ),
                ("bits", self.bits),
            ],
        )

Timestamp dataclass

Bases: YadsType

Timestamp type with implicit timezone awareness.

Parameters:

Name Type Description Default
unit TimeUnit | None

Smallest time unit for values. One of "s", "ms", "us", or "ns". Defaults to "ns".

NS
Source code in src/yads/types.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
@dataclass(frozen=True)
class Timestamp(YadsType):
    """Timestamp type with implicit timezone awareness.

    Args:
        unit: Smallest time unit for values. One of `"s"`, `"ms"`, `"us"`,
            or `"ns"`. Defaults to `"ns"`.
    """

    unit: TimeUnit | None = TimeUnit.NS

    def __post_init__(self):
        if not isinstance(self.unit, TimeUnit):
            allowed = {u.value for u in TimeUnit}
            raise TypeDefinitionError(
                f"Timestamp 'unit' must be one of {allowed}, not {self.unit}."
            )

    def __str__(self) -> str:
        return _format_type_str(
            "timestamp",
            [("unit", self.unit.value if isinstance(self.unit, TimeUnit) else self.unit)],
        )

TimestampTZ dataclass

Bases: YadsType

Timezone-aware timestamp type with explicit timezone information.

Parameters:

Name Type Description Default
unit TimeUnit | None

Smallest time unit for values. One of "s", "ms", "us", or "ns". Defaults to "ns".

NS
tz str

IANA timezone name to interpret values, for example "UTC" or "America/New_York". Must be a non-empty string. Defaults to "UTC".

'UTC'
Source code in src/yads/types.py
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
@dataclass(frozen=True)
class TimestampTZ(YadsType):
    """Timezone-aware timestamp type with explicit timezone information.

    Args:
        unit: Smallest time unit for values. One of `"s"`, `"ms"`, `"us"`,
            or `"ns"`. Defaults to `"ns"`.
        tz: IANA timezone name to interpret values, for example `"UTC"` or
            `"America/New_York"`. Must be a non-empty string. Defaults to
            `"UTC"`.
    """

    unit: TimeUnit | None = TimeUnit.NS
    tz: str = "UTC"

    def __post_init__(self):
        if not isinstance(self.unit, TimeUnit):
            allowed = {u.value for u in TimeUnit}
            raise TypeDefinitionError(
                f"TimestampTZ 'unit' must be one of {allowed}, not {self.unit}."
            )
        if self.tz is None:  # pyright: ignore[reportUnnecessaryComparison]
            raise TypeDefinitionError(
                "TimestampTZ 'tz' must not be None. Use Timestamp or TimestampNTZ for no timezone."
            )
        if isinstance(self.tz, str) and not self.tz:  # pyright: ignore[reportUnnecessaryIsInstance]
            raise TypeDefinitionError("TimestampTZ 'tz' must be a non-empty string.")

    def __str__(self) -> str:
        return _format_type_str(
            "timestamptz",
            [
                (
                    "unit",
                    self.unit.value if isinstance(self.unit, TimeUnit) else self.unit,
                ),
                ("tz", self.tz),
            ],
        )

TimestampLTZ dataclass

Bases: YadsType

Timezone-aware timestamp type with session-local timezone semantics.

Parameters:

Name Type Description Default
unit TimeUnit | None

Smallest time unit for values. One of "s", "ms", "us", or "ns". Defaults to "ns".

NS
Source code in src/yads/types.py
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
@dataclass(frozen=True)
class TimestampLTZ(YadsType):
    """Timezone-aware timestamp type with session-local timezone semantics.

    Args:
        unit: Smallest time unit for values. One of `"s"`, `"ms"`, `"us"`,
            or `"ns"`. Defaults to `"ns"`.
    """

    unit: TimeUnit | None = TimeUnit.NS

    def __post_init__(self):
        if not isinstance(self.unit, TimeUnit):
            allowed = {u.value for u in TimeUnit}
            raise TypeDefinitionError(
                f"TimestampLTZ 'unit' must be one of {allowed}, not {self.unit}."
            )

    def __str__(self) -> str:
        return _format_type_str(
            "timestampltz",
            [("unit", self.unit.value if isinstance(self.unit, TimeUnit) else self.unit)],
        )

TimestampNTZ dataclass

Bases: YadsType

Timestamp type with explicit timezone unawareness.

Parameters:

Name Type Description Default
unit TimeUnit | None

Smallest time unit for values. One of "s", "ms", "us", or "ns". Defaults to "ns".

NS
Source code in src/yads/types.py
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
@dataclass(frozen=True)
class TimestampNTZ(YadsType):
    """Timestamp type with explicit timezone unawareness.

    Args:
        unit: Smallest time unit for values. One of `"s"`, `"ms"`, `"us"`,
            or `"ns"`. Defaults to `"ns"`.
    """

    unit: TimeUnit | None = TimeUnit.NS

    def __post_init__(self):
        if not isinstance(self.unit, TimeUnit):
            allowed = {u.value for u in TimeUnit}
            raise TypeDefinitionError(
                f"TimestampNTZ 'unit' must be one of {allowed}, not {self.unit}."
            )

    def __str__(self) -> str:
        return _format_type_str(
            "timestampntz",
            [("unit", self.unit.value if isinstance(self.unit, TimeUnit) else self.unit)],
        )

Duration dataclass

Bases: YadsType

Logical duration type with fractional precision.

Represents an elapsed amount of time. Precision is expressed via a unit granularity.

Parameters:

Name Type Description Default
unit TimeUnit | None

Smallest time unit for values. One of "s", "ms", "us", or "ns". Defaults to "ns".

NS

Raises:

Type Description
TypeDefinitionError

If unit is not one of the supported values.

Source code in src/yads/types.py
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
@dataclass(frozen=True)
class Duration(YadsType):
    """Logical duration type with fractional precision.

    Represents an elapsed amount of time. Precision is expressed via a unit
    granularity.

    Args:
        unit: Smallest time unit for values. One of `"s"`, `"ms"`, `"us"`,
            or `"ns"`. Defaults to `"ns"`.

    Raises:
        TypeDefinitionError: If `unit` is not one of the supported values.
    """

    unit: TimeUnit | None = TimeUnit.NS

    def __post_init__(self):
        if not isinstance(self.unit, TimeUnit):
            allowed = {u.value for u in TimeUnit}
            raise TypeDefinitionError(
                f"Duration 'unit' must be one of {allowed}, not {self.unit}."
            )

    def __str__(self) -> str:
        return _format_type_str(
            "duration",
            [("unit", self.unit.value if isinstance(self.unit, TimeUnit) else self.unit)],
        )

IntervalTimeUnit

Bases: str, Enum

Time unit enumeration for interval types.

Defines the valid time units that can be used in interval type definitions. Units are categorized into Year-Month and Day-Time groups for SQL compatibility.

Source code in src/yads/types.py
485
486
487
488
489
490
491
492
493
494
495
496
497
498
class IntervalTimeUnit(str, Enum):
    """Time unit enumeration for interval types.

    Defines the valid time units that can be used in interval type
    definitions. Units are categorized into Year-Month and Day-Time
    groups for SQL compatibility.
    """

    YEAR = "YEAR"
    MONTH = "MONTH"
    DAY = "DAY"
    HOUR = "HOUR"
    MINUTE = "MINUTE"
    SECOND = "SECOND"

Interval dataclass

Bases: YadsType

Time interval type representing a duration between two time points. The interval is defined by start and optional end time units.

Parameters:

Name Type Description Default
interval_start IntervalTimeUnit

The starting (most significant) time unit.

required
interval_end IntervalTimeUnit | None

The ending (least significant) time unit. If None, represents a single-unit interval.

None
The start and end units must belong to the same category
  • Year-Month: YEAR, MONTH
  • Day-Time: DAY, HOUR, MINUTE, SECOND

Raises:

Type Description
TypeDefinitionError

If start and end units are from different categories, or if start is less significant than end.

Source code in src/yads/types.py
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
@dataclass(frozen=True)
class Interval(YadsType):
    """Time interval type representing a duration between two time points. The interval
    is defined by start and optional end time units.

    Args:
        interval_start: The starting (most significant) time unit.
        interval_end: The ending (least significant) time unit. If None,
                     represents a single-unit interval.


    The start and end units must belong to the same category:
        - Year-Month: `YEAR`, `MONTH`
        - Day-Time: `DAY`, `HOUR`, `MINUTE`, `SECOND`

    Raises:
        TypeDefinitionError: If start and end units are from different categories,
                           or if start is less significant than end.
    """

    interval_start: IntervalTimeUnit
    interval_end: IntervalTimeUnit | None = None

    def __post_init__(self):
        _UNIT_ORDER_MAP = {
            "Year-Month": [IntervalTimeUnit.YEAR, IntervalTimeUnit.MONTH],
            "Day-Time": [
                IntervalTimeUnit.DAY,
                IntervalTimeUnit.HOUR,
                IntervalTimeUnit.MINUTE,
                IntervalTimeUnit.SECOND,
            ],
        }

        if self.interval_end:
            in_ym_start = self.interval_start in _UNIT_ORDER_MAP["Year-Month"]
            in_ym_end = self.interval_end in _UNIT_ORDER_MAP["Year-Month"]

            if in_ym_start != in_ym_end:
                category_start = "Year-Month" if in_ym_start else "Day-Time"
                category_end = "Year-Month" if in_ym_end else "Day-Time"
                raise TypeDefinitionError(
                    "Invalid Interval definition: 'interval_start' and 'interval_end' must "
                    "belong to the same category (either Year-Month or Day-Time). "
                    f"Received interval_start='{self.interval_start.value}' (category: "
                    f"{category_start}) and interval_end='{self.interval_end.value}' "
                    f"(category: {category_end})."
                )

        category = (
            "Year-Month"
            if self.interval_start in _UNIT_ORDER_MAP["Year-Month"]
            else "Day-Time"
        )
        order = _UNIT_ORDER_MAP[category]

        if self.interval_end and self.interval_start != self.interval_end:
            start_index = order.index(self.interval_start)
            end_index = order.index(self.interval_end)
            if start_index > end_index:
                raise TypeDefinitionError(
                    "Invalid Interval definition: 'interval_start' cannot be less "
                    "significant than 'interval_end'. "
                    f"Received interval_start='{self.interval_start.value}' and "
                    f"interval_end='{self.interval_end.value}'."
                )

    def __str__(self) -> str:
        if self.interval_end and self.interval_start != self.interval_end:
            return _format_type_str(
                "interval",
                [
                    ("interval_start", self.interval_start.value),
                    ("interval_end", self.interval_end.value),
                ],
            )
        return _format_type_str(
            "interval", [("interval_start", self.interval_start.value)]
        )

Array dataclass

Bases: YadsType

Array type containing elements of a homogeneous type.

Represents ordered collections where all elements share the same type.

Parameters:

Name Type Description Default
element YadsType

The type of elements contained in the array.

required
size int | None

Optional maximum size for fixed-size arrays. If None, the array is variable-length.

None
Example
# Array of strings
Array(element=String())

# Fixed-size array of integers
Array(element=Integer(bits=32), size=10)

# Nested array (array of arrays)
Array(element=Array(element=String()))
Source code in src/yads/types.py
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
@dataclass(frozen=True)
class Array(YadsType):
    """Array type containing elements of a homogeneous type.

    Represents ordered collections where all elements share the same type.

    Args:
        element: The type of elements contained in the array.
        size: Optional maximum size for fixed-size arrays. If None, the
            array is variable-length.

    Example:
        ```python
        # Array of strings
        Array(element=String())

        # Fixed-size array of integers
        Array(element=Integer(bits=32), size=10)

        # Nested array (array of arrays)
        Array(element=Array(element=String()))
        ```
    """

    element: YadsType
    size: int | None = None

    def __str__(self) -> str:
        if self.size is not None:
            return f"array<{self.element}, size={self.size}>"
        return f"array<{self.element}>"

Struct dataclass

Bases: YadsType

Structured type containing named fields of potentially different types.

Represents complex objects with named fields.

Parameters:

Name Type Description Default
fields list[Field]

List of Field objects defining the structure's schema.

required
Example
from yads.spec import Field

# Address structure
address_type = Struct(fields=[
    Field(name="street", type=String()),
    Field(name="city", type=String()),
    Field(name="postal_code", type=String(length=10))
])

# Nested structures
person_type = Struct(fields=[
    Field(name="name", type=String()),
    Field(name="age", type=Integer()),
    Field(name="address", type=address_type)
])
Source code in src/yads/types.py
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
@dataclass(frozen=True)
class Struct(YadsType):
    """Structured type containing named fields of potentially different types.

    Represents complex objects with named fields.

    Args:
        fields: List of Field objects defining the structure's schema.

    Example:
        ```python
        from yads.spec import Field

        # Address structure
        address_type = Struct(fields=[
            Field(name="street", type=String()),
            Field(name="city", type=String()),
            Field(name="postal_code", type=String(length=10))
        ])

        # Nested structures
        person_type = Struct(fields=[
            Field(name="name", type=String()),
            Field(name="age", type=Integer()),
            Field(name="address", type=address_type)
        ])
        ```
    """

    fields: list[Field]

    def __str__(self) -> str:
        fields_str = ",\n".join(str(field) for field in self.fields)
        indented_fields = textwrap.indent(fields_str, "  ")
        return f"struct<\n{indented_fields}\n>"

Map dataclass

Bases: YadsType

Key-value mapping type with homogeneous key and value types.

Represents associative arrays or dictionaries where all keys share one type and all values share another type.

Parameters:

Name Type Description Default
key YadsType

The type of all keys in the map.

required
value YadsType

The type of all values in the map.

required
keys_sorted bool

Whether the map has sorted keys. Defaults to False.

False
Example
# String-to-string mapping
Map(key=String(), value=String())

# String-to-integer mapping
Map(key=String(), value=Integer())

# Complex value types
Map(key=String(), value=Array(element=String()))
Source code in src/yads/types.py
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
@dataclass(frozen=True)
class Map(YadsType):
    """Key-value mapping type with homogeneous key and value types.

    Represents associative arrays or dictionaries where all keys share one type
    and all values share another type.

    Args:
        key: The type of all keys in the map.
        value: The type of all values in the map.
        keys_sorted: Whether the map has sorted keys. Defaults to False.

    Example:
        ```python
        # String-to-string mapping
        Map(key=String(), value=String())

        # String-to-integer mapping
        Map(key=String(), value=Integer())

        # Complex value types
        Map(key=String(), value=Array(element=String()))
        ```
    """

    key: YadsType
    value: YadsType
    keys_sorted: bool = False

    def __str__(self) -> str:
        if self.keys_sorted:
            return f"map<{self.key}, {self.value}, keys_sorted=True>"
        return f"map<{self.key}, {self.value}>"

JSON dataclass

Bases: YadsType

JSON document type for semi-structured data.

Source code in src/yads/types.py
687
688
689
@dataclass(frozen=True)
class JSON(YadsType):
    """JSON document type for semi-structured data."""

Geometry dataclass

Bases: YadsType

Geometric object type with optional SRID.

Represents planar geometry values such as points, linestrings, and polygons.

Parameters:

Name Type Description Default
srid int | str | None

Spatial reference identifier, for example an integer code or the string "ANY". If None, no SRID is rendered.

None
Source code in src/yads/types.py
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
@dataclass(frozen=True)
class Geometry(YadsType):
    """Geometric object type with optional SRID.

    Represents planar geometry values such as points, linestrings, and polygons.

    Args:
        srid: Spatial reference identifier, for example an integer code or
            the string `"ANY"`. If `None`, no SRID is rendered.
    """

    srid: int | str | None = None

    def __str__(self) -> str:
        if self.srid is None:
            return "geometry"
        return _format_type_str("geometry", [("srid", self.srid)])

Geography dataclass

Bases: YadsType

Geographic object type with optional SRID.

Represents geographic values in a spherical coordinate system.

Parameters:

Name Type Description Default
srid int | str | None

Spatial reference identifier, e.g., integer code or the string "ANY". If None, no SRID is rendered.

None
Source code in src/yads/types.py
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
@dataclass(frozen=True)
class Geography(YadsType):
    """Geographic object type with optional SRID.

    Represents geographic values in a spherical coordinate system.

    Args:
        srid: Spatial reference identifier, e.g., integer code or the string
            `"ANY"`. If `None`, no SRID is rendered.
    """

    srid: int | str | None = None

    def __str__(self) -> str:
        if self.srid is None:
            return "geography"
        return _format_type_str("geography", [("srid", self.srid)])

UUID dataclass

Bases: YadsType

Universally Unique Identifier type. Represents 128-bit UUID values.

Source code in src/yads/types.py
730
731
732
@dataclass(frozen=True)
class UUID(YadsType):
    """Universally Unique Identifier type. Represents 128-bit UUID values."""

Void dataclass

Bases: YadsType

Represents a NULL or VOID type.

Source code in src/yads/types.py
735
736
737
@dataclass(frozen=True)
class Void(YadsType):
    """Represents a NULL or VOID type."""

Variant dataclass

Bases: YadsType

Variant type representing a union of potentially different types.

Source code in src/yads/types.py
740
741
742
@dataclass(frozen=True)
class Variant(YadsType):
    """Variant type representing a union of potentially different types."""

Tensor dataclass

Bases: YadsType

Multi-dimensional tensors with fixed shape and a canonical element base type.

Parameters:

Name Type Description Default
element YadsType

The type of elements in the tensor.

required
shape tuple[int, ...]

Tuple of positive integers defining tensor dimensions.

required

Raises:

Type Description
TypeDefinitionError

If shape is empty or contains non-positive integers.

Example
# 2D tensor of integers
Tensor(element=Integer(), shape=[10, 20])

# 3D tensor of floats
Tensor(element=Float(bits=32), shape=[5, 10, 15])

# Use in field definition
Field(name="image_data", type=Tensor(element=Float(bits=32), shape=[224, 224, 3]))
Source code in src/yads/types.py
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
@dataclass(frozen=True)
class Tensor(YadsType):
    """Multi-dimensional tensors with fixed shape and a canonical element base type.

    Args:
        element: The type of elements in the tensor.
        shape: Tuple of positive integers defining tensor dimensions.

    Raises:
        TypeDefinitionError: If shape is empty or contains non-positive integers.

    Example:
        ```python
        # 2D tensor of integers
        Tensor(element=Integer(), shape=[10, 20])

        # 3D tensor of floats
        Tensor(element=Float(bits=32), shape=[5, 10, 15])

        # Use in field definition
        Field(name="image_data", type=Tensor(element=Float(bits=32), shape=[224, 224, 3]))
        ```
    """

    element: YadsType
    shape: tuple[int, ...]

    def __post_init__(self):
        if not self.shape:
            raise TypeDefinitionError("Tensor 'shape' cannot be empty.")
        if not all(isinstance(dim, int) and dim > 0 for dim in self.shape):  # pyright: ignore[reportUnnecessaryIsInstance]
            raise TypeDefinitionError(
                f"Tensor 'shape' must contain only positive integers, got {self.shape}."
            )

    def __str__(self) -> str:
        shape_str = "[" + ", ".join(map(str, self.shape)) + "]"
        return f"tensor<{self.element}, shape={shape_str}>"