RootModel
RootModel class and type definitions.
RootModel
Section titled “RootModel”Bases: BaseModel, Generic[RootModelRootType]
A Pydantic BaseModel for the root object of the model.
Attributes
Section titled “Attributes”The root object of the model.
Type: RootModelRootType
__pydantic_root_model__
Section titled “__pydantic_root_model__”Whether the model is a RootModel.
__pydantic_private__
Section titled “__pydantic_private__”Private fields in the model.
__pydantic_extra__
Section titled “__pydantic_extra__”Extra fields in the model.
Methods
Section titled “Methods”model_construct
Section titled “model_construct”@classmethod
def model_construct(
cls,
root: RootModelRootType,
_fields_set: set[str] | None = None,
) -> SelfCreate a new model using the provided root object and update fields set.
Returns
Section titled “Returns”Self — The new model.
Parameters
Section titled “Parameters”root : RootModelRootType
The root object of the model.
_fields_set : set[str] | None Default: None
The set of fields to be updated.
Raises
Section titled “Raises”NotImplemented— If the model is not a subclass ofRootModel.
model_dump
Section titled “model_dump”def model_dump(
*,
mode: Literal['json', 'python'] | str = 'python',
include: Any = None,
exclude: Any = None,
context: dict[str, Any] | None = None,
by_alias: bool | None = None,
exclude_unset: bool = False,
exclude_defaults: bool = False,
exclude_none: bool = False,
exclude_computed_fields: bool = False,
round_trip: bool = False,
warnings: bool | Literal['none', 'warn', 'error'] = True,
serialize_as_any: bool = False,
) -> AnyThis method is included just to get a more accurate return type for type checkers. It is included in this if TYPE_CHECKING: block since no override is actually necessary.
See the documentation of BaseModel.model_dump for more details about the arguments.
Generally, this method will have a return type of RootModelRootType, assuming that RootModelRootType is not a BaseModel subclass. If RootModelRootType is a BaseModel subclass, then the return type will likely be dict[str, Any], as model_dump calls are recursive. The return type could even be something different, in the case of a custom serializer. Thus, Any is used here to catch all of these cases.
Returns
Section titled “Returns”Was this page helpful?