tuple_schema
Returns a schema that matches a tuple of schemas, with an optional variadic item, e.g.:
from pydantic_core import SchemaValidator, core_schema
schema = core_schema.tuple_schema(
[core_schema.int_schema(), core_schema.str_schema(), core_schema.float_schema()],
variadic_item_index=1,
)
v = SchemaValidator(schema)
assert v.validate_python((1, 'hello', 'world', 1.5)) == (1, 'hello', 'world', 1.5)
def tuple_schema(
items_schema: list[CoreSchema],
variadic_item_index: int | None = None,
min_length: int | None = None,
max_length: int | None = None,
fail_fast: bool | None = None,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: IncExSeqOrElseSerSchema | None = None
) - > TupleSchema
Returns a schema that matches a tuple of schemas, with an optional variadic item.
Parameters
| Name | Type | Description |
|---|---|---|
| items_schema | list[CoreSchema] | The list of schemas that each corresponding item in the tuple must match. |
| variadic_item_index | `int | None` = None |
| min_length | `int | None` = None |
| max_length | `int | None` = None |
| fail_fast | `bool | None` = None |
| strict | `bool | None` = None |
| ref | `str | None` = None |
| metadata | `dict[str, Any] | None` = None |
| serialization | `IncExSeqOrElseSerSchema | None` = None |
Returns
| Type | Description |
|---|---|
TupleSchema | A core schema dictionary representing a tuple validation structure. |