RootModel
A Pydantic BaseModel for the root object of the model.
Attributes
| Attribute | Type | Description |
|---|---|---|
| root | RootModelRootType | The root object of the model. |
Constructor
Signature
def RootModel(
root: RootModelRootType = PydanticUndefined,
**data: Any
) - > None
Parameters
| Name | Type | Description |
|---|---|---|
| root | RootModelRootType = PydanticUndefined | The root object of the model, passed as a positional-only argument. |
| **data | Any | Arbitrary 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
| Name | Type | Description |
|---|---|---|
| root | RootModelRootType | The root object of the model. |
| _fields_set | `set[str] | None` |
Returns
| Type | Description |
|---|---|
Self | The 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
| Name | Type | Description |
|---|---|---|
| mode | `Literal['json', 'python'] | str` |
| include | Any | Fields to include in the output. |
| exclude | Any | Fields to exclude from the output. |
| context | `dict[str, Any] | None` |
| by_alias | `bool | None` |
| exclude_unset | bool | Whether to exclude fields that were not explicitly set. |
| exclude_defaults | bool | Whether to exclude fields equal to their default values. |
| exclude_none | bool | Whether to exclude fields with None values. |
| exclude_computed_fields | bool | Whether to exclude properties decorated with @computed_field. |
| round_trip | bool | Whether to ensure the output can be loaded back into the model. |
| warnings | `bool | Literal['none', 'warn', 'error']` |
| serialize_as_any | bool | Whether to serialize the object using its actual type rather than the declared type. |
Returns
| Type | Description |
|---|---|
Any | The serialized representation of the root object, which varies based on the root type and serialization settings. |