Skip to main content

RootModel

A Pydantic BaseModel for the root object of the model.

Attributes

AttributeTypeDescription
rootRootModelRootTypeThe root object of the model.

Constructor

Signature

def RootModel(
root: RootModelRootType = PydanticUndefined,
**data: Any
) - > None

Parameters

NameTypeDescription
rootRootModelRootType = PydanticUndefinedThe root object of the model, passed as a positional-only argument.
**dataAnyArbitrary keyword arguments to be used as the root object if the positional root argument is not provided.

Methods


model_construct()

@classmethod
def model_construct(
root: RootModelRootType,
_fields_set: set[str]| None
) - > Self

Create a new model using the provided root object and update fields set.

Parameters

NameTypeDescription
rootRootModelRootTypeThe root object of the model.
_fields_set`set[str]None`

Returns

TypeDescription
SelfThe new model.

model_dump()

@classmethod
def model_dump(
mode: Literal['json', 'python']| str,
include: Any,
exclude: Any,
context: dict[str, Any]| None,
by_alias: bool | None,
exclude_unset: bool,
exclude_defaults: bool,
exclude_none: bool,
exclude_computed_fields: bool,
round_trip: bool,
warnings: bool | Literal['none', 'warn', 'error'],
serialize_as_any: bool
) - > Any

Generates a representation of the model, typically used for serialization to JSON or Python dictionaries.

Parameters

NameTypeDescription
mode`Literal['json', 'python']str`
includeAnyFields to include in the output.
excludeAnyFields to exclude from the output.
context`dict[str, Any]None`
by_alias`boolNone`
exclude_unsetboolWhether to exclude fields that were not explicitly set.
exclude_defaultsboolWhether to exclude fields equal to their default values.
exclude_noneboolWhether to exclude fields with None values.
exclude_computed_fieldsboolWhether to exclude properties decorated with @computed_field.
round_tripboolWhether to ensure the output can be loaded back into the model.
warnings`boolLiteral['none', 'warn', 'error']`
serialize_as_anyboolWhether to serialize the object using its actual type rather than the declared type.

Returns

TypeDescription
AnyThe serialized representation of the root object, which varies based on the root type and serialization settings.