RootModel
RootModel class and type definitions.
Bases: BaseModel, Generic[RootModelRootType]
A Pydantic BaseModel for the root object of the model.
The root object of the model.
Type: RootModelRootType
Whether the model is a RootModel.
Private fields in the model.
Extra fields in the model.
@classmethod
def model_construct(
cls,
root: RootModelRootType,
_fields_set: set[str] | None = None,
) -> Self
Create a new model using the provided root object and update fields set.
Self — The new model.
The root object of the model.
The set of fields to be updated.
NotImplemented— If the model is not a subclass ofRootModel.
def model_dump(
*,
mode: Literal['json', 'python'] | str = 'python',
include: IncEx | None = None,
exclude: IncEx | None = None,
context: 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,
fallback: Callable[[Any], Any] | None = None,
serialize_as_any: bool = False,
polymorphic_serialization: bool | None = None,
) -> Any
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
Any — A dictionary representation of the model.
The mode in which to_python should run.
If mode is ‘json’, the output will only contain JSON serializable types.
If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include : IncEx | None Default: None
A set of fields to include in the output.
exclude : IncEx | None Default: None
A set of fields to exclude from the output.
Additional context to pass to the serializer.
Whether to use the field’s alias in the dictionary key if defined.
exclude_unset : bool Default: False
Whether to exclude fields that have not been explicitly set.
exclude_defaults : bool Default: False
Whether to exclude fields that are set to their default value.
exclude_none : bool Default: False
Whether to exclude fields that have a value of None.
exclude_computed_fields : bool Default: False
Whether to exclude computed fields.
While this can be useful for round-tripping, it is usually recommended to use the dedicated
round_trip parameter instead.
round_trip : bool Default: False
If True, dumped values should be valid as input for non-idempotent types such as Json[T].
How to handle serialization errors. False/“none” ignores them, True/“warn” logs errors,
“error” raises a PydanticSerializationError.
A function to call when an unknown value is encountered. If not provided,
a PydanticSerializationError error is raised.
serialize_as_any : bool Default: False
Whether to serialize fields with duck-typing serialization behavior.
Whether to use model and dataclass polymorphic serialization for this call.