Skip to content
You're viewing docs for v2.10. See the latest version →

RootModel

RootModel class and type definitions.

PydanticUserError

Bases: PydanticErrorMixin, TypeError

An error raised due to incorrect use of Pydantic.


BaseModel

Usage docs: https://docs.pydantic.dev/2.10/concepts/models/

A base class for creating Pydantic models.

Attributes

model_config

Configuration for the model, should be a dictionary conforming to ConfigDict.

Type: ConfigDict Default: ConfigDict()

class_vars

The names of the class variables defined on the model.

Type: set[str]

private_attributes

Metadata about the private attributes of the model.

Type: Dict[str, ModelPrivateAttr]

signature

The synthesized __init__ Signature of the model.

Type: Signature

pydantic_complete

Whether model building is completed, or if there are still undefined fields.

Type: bool Default: False

pydantic_core_schema

The core schema of the model.

Type: CoreSchema

pydantic_custom_init

Whether the model has a custom __init__ method.

Type: bool

pydantic_decorators

Metadata containing the decorators defined on the model. This replaces Model.__validators__ and Model.__root_validators__ from Pydantic V1.

Type: _decorators.DecoratorInfos Default: _decorators.DecoratorInfos()

pydantic_generic_metadata

Metadata for generic models; contains data used for a similar purpose to args, origin, parameters in typing-module generics. May eventually be replaced by these.

Type: _generics.PydanticGenericMetadata

pydantic_parent_namespace

Parent namespace of the model, used for automatic rebuilding of models.

Type: Dict[str, Any] | None Default: None

pydantic_post_init

The name of the post-init method for the model, if defined.

Type: None | Literal['model_post_init']

pydantic_root_model

Whether the model is a RootModel.

Type: bool Default: False

pydantic_serializer

The pydantic-core SchemaSerializer used to dump instances of the model.

Type: SchemaSerializer

pydantic_validator

The pydantic-core SchemaValidator used to validate instances of the model.

Type: SchemaValidator | PluggableSchemaValidator

pydantic_fields

A dictionary of field names and their corresponding FieldInfo objects. This replaces Model.__fields__ from Pydantic V1.

Type: Dict[str, FieldInfo]

pydantic_computed_fields

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

Type: Dict[str, ComputedFieldInfo]

pydantic_extra

A dictionary containing extra values, if extra is set to 'allow'.

Type: dict[str, Any] | None Default: _model_construction.NoInitField(init=False)

pydantic_fields_set

The names of fields explicitly set during instantiation.

Type: set[str] Default: _model_construction.NoInitField(init=False)

pydantic_private

Values of private attributes set on the model instance.

Type: dict[str, Any] | None Default: _model_construction.NoInitField(init=False)

model_fields

Get metadata about the fields defined on the model.

Deprecation warning: you should be getting this information from the model class, not from an instance. In V3, this property will be removed from the BaseModel class.

Type: dict[str, FieldInfo]

model_computed_fields

Get metadata about the computed fields defined on the model.

Deprecation warning: you should be getting this information from the model class, not from an instance. In V3, this property will be removed from the BaseModel class.

Type: dict[str, ComputedFieldInfo]

model_extra

Get extra fields set during validation.

Type: dict[str, Any] | None

model_fields_set

Returns the set of fields that have been explicitly set on this model instance.

Type: set[str]

Methods

init

def __init__(data: Any = {}) -> None

Create a new model by parsing and validating input data from keyword arguments.

Raises ValidationError if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Returns

None

model_construct

@classmethod

def model_construct(cls, _fields_set: set[str] | None = None, values: Any = {}) -> Self

Creates a new instance of the Model class with validated data.

Creates a new model setting __dict__ and __pydantic_fields_set__ from trusted or pre-validated data. Default values are respected, but no other validation is performed.

Returns

Self — A new instance of the Model class with validated data.

Parameters

_fields_set : set[str] | None Default: None

A set of field names that were originally explicitly set during instantiation. If provided, this is directly used for the model_fields_set attribute. Otherwise, the field names from the values argument will be used.

values : Any Default: \{\}

Trusted or pre-validated data dictionary.

model_copy

def model_copy(update: Mapping[str, Any] | None = None, deep: bool = False) -> Self

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#model_copy

Returns a copy of the model.

Returns

Self — New model instance.

Parameters

update : Mapping[str, Any] | None Default: None

Values to change/add in the new model. Note: the data is not validated before creating the new model. You should trust this data.

deep : bool Default: False

Set to True to make a deep copy of the model.

model_dump

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

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump

Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.

Returns

dict[str, Any] — A dictionary representation of the model.

Parameters

mode : Literal['json', 'python'] | str Default: 'python'

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.

context : Any | None Default: None

Additional context to pass to the serializer.

by_alias : bool Default: False

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.

round_trip : bool Default: False

If True, dumped values should be valid as input for non-idempotent types such as Json[T].

warnings : bool | Literal['none', 'warn', 'error'] Default: True

How to handle serialization errors. False/“none” ignores them, True/“warn” logs errors, “error” raises a PydanticSerializationError.

serialize_as_any : bool Default: False

Whether to serialize fields with duck-typing serialization behavior.

model_dump_json

def model_dump_json(
    indent: int | None = None,
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    context: Any | None = None,
    by_alias: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    round_trip: bool = False,
    warnings: bool | Literal['none', 'warn', 'error'] = True,
    serialize_as_any: bool = False,
) -> str

Usage docs: https://docs.pydantic.dev/2.10/concepts/serialization/#modelmodel_dump_json

Generates a JSON representation of the model using Pydantic’s to_json method.

Returns

str — A JSON string representation of the model.

Parameters

indent : int | None Default: None

Indentation to use in the JSON output. If None is passed, the output will be compact.

include : IncEx | None Default: None

Field(s) to include in the JSON output.

exclude : IncEx | None Default: None

Field(s) to exclude from the JSON output.

context : Any | None Default: None

Additional context to pass to the serializer.

by_alias : bool Default: False

Whether to serialize using field aliases.

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.

round_trip : bool Default: False

If True, dumped values should be valid as input for non-idempotent types such as Json[T].

warnings : bool | Literal['none', 'warn', 'error'] Default: True

How to handle serialization errors. False/“none” ignores them, True/“warn” logs errors, “error” raises a PydanticSerializationError.

serialize_as_any : bool Default: False

Whether to serialize fields with duck-typing serialization behavior.

model_json_schema

@classmethod

def model_json_schema(
    cls,
    by_alias: bool = True,
    ref_template: str = DEFAULT_REF_TEMPLATE,
    schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
    mode: JsonSchemaMode = 'validation',
) -> dict[str, Any]

Generates a JSON schema for a model class.

Returns

dict[str, Any] — The JSON schema for the given model class.

Parameters

by_alias : bool Default: True

Whether to use attribute aliases or not.

ref_template : str Default: DEFAULT_REF_TEMPLATE

The reference template.

schema_generator : type[GenerateJsonSchema] Default: GenerateJsonSchema

To override the logic used to generate the JSON schema, as a subclass of GenerateJsonSchema with your desired modifications

mode : JsonSchemaMode Default: 'validation'

The mode in which to generate the schema.

model_parametrized_name

@classmethod

def model_parametrized_name(cls, params: tuple[type[Any], ...]) -> str

Compute the class name for parametrizations of generic classes.

This method can be overridden to achieve a custom naming scheme for generic BaseModels.

Returns

str — String representing the new class where params are passed to cls as type variables.

Parameters

params : tuple[type[Any], ...]

Tuple of types of the class. Given a generic class Model with 2 type variables and a concrete model Model[str, int], the value (str, int) would be passed to params.

Raises
  • TypeError — Raised when trying to generate concrete names for non-generic models.

model_post_init

def model_post_init(__context: Any) -> None

Override this method to perform additional initialization after __init__ and model_construct. This is useful if you want to do some validation that requires the entire model to be initialized.

Returns

None

model_rebuild

@classmethod

def model_rebuild(
    cls,
    force: bool = False,
    raise_errors: bool = True,
    _parent_namespace_depth: int = 2,
    _types_namespace: MappingNamespace | None = None,
) -> bool | None

Try to rebuild the pydantic-core schema for the model.

This may be necessary when one of the annotations is a ForwardRef which could not be resolved during the initial attempt to build the schema, and automatic rebuilding fails.

Returns

bool | None — Returns None if the schema is already “complete” and rebuilding was not required. bool | None — If rebuilding was required, returns True if rebuilding was successful, otherwise False.

Parameters

force : bool Default: False

Whether to force the rebuilding of the model schema, defaults to False.

raise_errors : bool Default: True

Whether to raise errors, defaults to True.

_parent_namespace_depth : int Default: 2

The depth level of the parent namespace, defaults to 2.

_types_namespace : MappingNamespace | None Default: None

The types namespace, defaults to None.

model_validate

@classmethod

def model_validate(
    cls,
    obj: Any,
    strict: bool | None = None,
    from_attributes: bool | None = None,
    context: Any | None = None,
) -> Self

Validate a pydantic model instance.

Returns

Self — The validated model instance.

Parameters

obj : Any

The object to validate.

strict : bool | None Default: None

Whether to enforce types strictly.

from_attributes : bool | None Default: None

Whether to extract data from object attributes.

context : Any | None Default: None

Additional context to pass to the validator.

Raises
  • ValidationError — If the object could not be validated.

model_validate_json

@classmethod

def model_validate_json(
    cls,
    json_data: str | bytes | bytearray,
    strict: bool | None = None,
    context: Any | None = None,
) -> Self

Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing

Validate the given JSON data against the Pydantic model.

Returns

Self — The validated Pydantic model.

Parameters

json_data : str | bytes | bytearray

The JSON data to validate.

strict : bool | None Default: None

Whether to enforce types strictly.

context : Any | None Default: None

Extra variables to pass to the validator.

Raises
  • ValidationError — If json_data is not a JSON string or the object could not be validated.

model_validate_strings

@classmethod

def model_validate_strings(
    cls,
    obj: Any,
    strict: bool | None = None,
    context: Any | None = None,
) -> Self

Validate the given object with string data against the Pydantic model.

Returns

Self — The validated Pydantic model.

Parameters

obj : Any

The object containing string data to validate.

strict : bool | None Default: None

Whether to enforce types strictly.

context : Any | None Default: None

Extra variables to pass to the validator.

get_pydantic_core_schema

@classmethod

def __get_pydantic_core_schema__(
    cls,
    source: type[BaseModel],
    handler: GetCoreSchemaHandler,
) -> CoreSchema

Hook into generating the model’s CoreSchema.

Returns

CoreSchema — A pydantic-core CoreSchema.

Parameters

source : type[BaseModel]

The class we are generating a schema for. This will generally be the same as the cls argument if this is a classmethod.

handler : GetCoreSchemaHandler

A callable that calls into Pydantic’s internal CoreSchema generation logic.

get_pydantic_json_schema

@classmethod

def __get_pydantic_json_schema__(
    cls,
    core_schema: CoreSchema,
    handler: GetJsonSchemaHandler,
) -> JsonSchemaValue

Hook into generating the model’s JSON schema.

Returns

JsonSchemaValue — A JSON schema, as a Python object.

Parameters

core_schema : CoreSchema

A pydantic-core CoreSchema. You can ignore this argument and call the handler with a new CoreSchema, wrap this CoreSchema (\{'type': 'nullable', 'schema': current_schema\}), or just call the handler with the original schema.

handler : GetJsonSchemaHandler

Call into Pydantic’s internal JSON schema generation. This will raise a pydantic.errors.PydanticInvalidForJsonSchema if JSON schema generation fails. Since this gets called by BaseModel.model_json_schema you can override the schema_generator argument to that function to change JSON schema generation globally for a type.

pydantic_init_subclass

@classmethod

def __pydantic_init_subclass__(cls, kwargs: Any = {}) -> None

This is intended to behave just like __init_subclass__, but is called by ModelMetaclass only after the class is actually fully initialized. In particular, attributes like model_fields will be present when this is called.

This is necessary because __init_subclass__ will always be called by type.__new__, and it would require a prohibitively large refactor to the ModelMetaclass to ensure that type.__new__ was called in such a manner that the class would already be sufficiently initialized.

This will receive the same kwargs that would be passed to the standard __init_subclass__, namely, any kwargs passed to the class definition that aren’t used internally by pydantic.

Returns

None

Parameters

**kwargs : Any Default: \{\}

Any keyword arguments passed to the class definition that aren’t used internally by pydantic.

copy

def __copy__() -> Self

Returns a shallow copy of the model.

Returns

Self

deepcopy

def __deepcopy__(memo: dict[int, Any] | None = None) -> Self

Returns a deep copy of the model.

Returns

Self

init_subclass

def __init_subclass__(cls, kwargs: Unpack[ConfigDict] = {})

This signature is included purely to help type-checkers check arguments to class declaration, which provides a way to conveniently set model_config key/value pairs.

from pydantic import BaseModel

class MyModel(BaseModel, extra='allow'): ...

However, this may be deceiving, since the actual calls to __init_subclass__ will not receive any of the config arguments, and will only receive any keyword arguments passed during class initialization that are not expected keys in ConfigDict. (This is due to the way ModelMetaclass.__new__ works.)

Parameters

**kwargs : Unpack[ConfigDict] Default: \{\}

Keyword arguments passed to the class definition, which set model_config

iter

def __iter__() -> TupleGenerator

So dict(model) works.

Returns

TupleGenerator

dict

def dict(
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    by_alias: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
) -> Dict[str, Any]
Returns

Dict[str, Any]

json

def json(
    include: IncEx | None = None,
    exclude: IncEx | None = None,
    by_alias: bool = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    encoder: Callable[[Any], Any] | None = PydanticUndefined,
    models_as_dict: bool = PydanticUndefined,
    dumps_kwargs: Any = {},
) -> str
Returns

str

parse_obj

@classmethod

def parse_obj(cls, obj: Any) -> Self
Returns

Self

parse_raw

@classmethod

def parse_raw(
    cls,
    b: str | bytes,
    content_type: str | None = None,
    encoding: str = 'utf8',
    proto: DeprecatedParseProtocol | None = None,
    allow_pickle: bool = False,
) -> Self
Returns

Self

parse_file

@classmethod

def parse_file(
    cls,
    path: str | Path,
    content_type: str | None = None,
    encoding: str = 'utf8',
    proto: DeprecatedParseProtocol | None = None,
    allow_pickle: bool = False,
) -> Self
Returns

Self

from_orm

@classmethod

def from_orm(cls, obj: Any) -> Self
Returns

Self

construct

@classmethod

def construct(cls, _fields_set: set[str] | None = None, values: Any = {}) -> Self
Returns

Self

copy

def copy(
    include: AbstractSetIntStr | MappingIntStrAny | None = None,
    exclude: AbstractSetIntStr | MappingIntStrAny | None = None,
    update: Dict[str, Any] | None = None,
    deep: bool = False,
) -> Self

Returns a copy of the model.

If you need include or exclude, use:

data = self.model_dump(include=include, exclude=exclude, round_trip=True)
data = {**data, **(update or {})}
copied = self.model_validate(data)
Returns

Self — A copy of the model with included, excluded and updated fields as specified.

Parameters

include : AbstractSetIntStr | MappingIntStrAny | None Default: None

Optional set or mapping specifying which fields to include in the copied model.

exclude : AbstractSetIntStr | MappingIntStrAny | None Default: None

Optional set or mapping specifying which fields to exclude in the copied model.

update : Dict[str, Any] | None Default: None

Optional dictionary of field-value pairs to override field values in the copied model.

deep : bool Default: False

If True, the values of fields that are Pydantic models will be deep-copied.

schema

@classmethod

def schema(
    cls,
    by_alias: bool = True,
    ref_template: str = DEFAULT_REF_TEMPLATE,
) -> Dict[str, Any]
Returns

Dict[str, Any]

schema_json

@classmethod

def schema_json(
    cls,
    by_alias: bool = True,
    ref_template: str = DEFAULT_REF_TEMPLATE,
    dumps_kwargs: Any = {},
) -> str
Returns

str

validate

@classmethod

def validate(cls, value: Any) -> Self
Returns

Self

update_forward_refs

@classmethod

def update_forward_refs(cls, localns: Any = {}) -> None
Returns

None


RootModel

Bases: BaseModel, Generic[RootModelRootType]

Usage docs: https://docs.pydantic.dev/2.10/concepts/models/#rootmodel-and-custom-root-types

A Pydantic BaseModel for the root object of the model.

Attributes

root

Type: RootModelRootType

Methods

model_construct

@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.

Returns

Self — The new model.

Parameters

root : RootModelRootType

The root object of the model.

_fields_set : set[str] | None Default: None

The set of fields to be updated.

Raises
  • NotImplemented — If the model is not a subclass of RootModel.

copy

def __copy__() -> Self

Returns a shallow copy of the model.

Returns

Self

deepcopy

def __deepcopy__(memo: dict[int, Any] | None = None) -> Self

Returns a deep copy of the model.

Returns

Self

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 = False,
    exclude_unset: bool = False,
    exclude_defaults: bool = False,
    exclude_none: bool = False,
    round_trip: bool = False,
    warnings: bool | Literal['none', 'warn', 'error'] = True,
    serialize_as_any: bool = False,
) -> Any

This 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

Any


PydanticModelField

def PydanticModelField(
    default: ellipsis,
    alias: str | None = _Unset,
    alias_priority: int | None = _Unset,
    validation_alias: str | AliasPath | AliasChoices | None = _Unset,
    serialization_alias: str | None = _Unset,
    title: str | None = _Unset,
    field_title_generator: Callable[[str, FieldInfo], str] | None = _Unset,
    description: str | None = _Unset,
    examples: list[Any] | None = _Unset,
    exclude: bool | None = _Unset,
    discriminator: str | types.Discriminator | None = _Unset,
    deprecated: Deprecated | str | bool | None = _Unset,
    json_schema_extra: JsonDict | Callable[[JsonDict], None] | None = _Unset,
    frozen: bool | None = _Unset,
    validate_default: bool | None = _Unset,
    repr: bool = _Unset,
    init: bool | None = _Unset,
    init_var: bool | None = _Unset,
    kw_only: bool | None = _Unset,
    pattern: str | typing.Pattern[str] | None = _Unset,
    strict: bool | None = _Unset,
    coerce_numbers_to_str: bool | None = _Unset,
    gt: annotated_types.SupportsGt | None = _Unset,
    ge: annotated_types.SupportsGe | None = _Unset,
    lt: annotated_types.SupportsLt | None = _Unset,
    le: annotated_types.SupportsLe | None = _Unset,
    multiple_of: float | None = _Unset,
    allow_inf_nan: bool | None = _Unset,
    max_digits: int | None = _Unset,
    decimal_places: int | None = _Unset,
    min_length: int | None = _Unset,
    max_length: int | None = _Unset,
    union_mode: Literal['smart', 'left_to_right'] = _Unset,
    fail_fast: bool | None = _Unset,
    extra: Unpack[_EmptyKwargs] = {},
) -> Any
def PydanticModelField(
    default: _T,
    alias: str | None = _Unset,
    alias_priority: int | None = _Unset,
    validation_alias: str | AliasPath | AliasChoices | None = _Unset,
    serialization_alias: str | None = _Unset,
    title: str | None = _Unset,
    field_title_generator: Callable[[str, FieldInfo], str] | None = _Unset,
    description: str | None = _Unset,
    examples: list[Any] | None = _Unset,
    exclude: bool | None = _Unset,
    discriminator: str | types.Discriminator | None = _Unset,
    deprecated: Deprecated | str | bool | None = _Unset,
    json_schema_extra: JsonDict | Callable[[JsonDict], None] | None = _Unset,
    frozen: bool | None = _Unset,
    validate_default: bool | None = _Unset,
    repr: bool = _Unset,
    init: bool | None = _Unset,
    init_var: bool | None = _Unset,
    kw_only: bool | None = _Unset,
    pattern: str | typing.Pattern[str] | None = _Unset,
    strict: bool | None = _Unset,
    coerce_numbers_to_str: bool | None = _Unset,
    gt: annotated_types.SupportsGt | None = _Unset,
    ge: annotated_types.SupportsGe | None = _Unset,
    lt: annotated_types.SupportsLt | None = _Unset,
    le: annotated_types.SupportsLe | None = _Unset,
    multiple_of: float | None = _Unset,
    allow_inf_nan: bool | None = _Unset,
    max_digits: int | None = _Unset,
    decimal_places: int | None = _Unset,
    min_length: int | None = _Unset,
    max_length: int | None = _Unset,
    union_mode: Literal['smart', 'left_to_right'] = _Unset,
    fail_fast: bool | None = _Unset,
    extra: Unpack[_EmptyKwargs] = {},
) -> _T
def PydanticModelField(
    default_factory: Callable[[], _T] | Callable[[dict[str, Any]], _T],
    alias: str | None = _Unset,
    alias_priority: int | None = _Unset,
    validation_alias: str | AliasPath | AliasChoices | None = _Unset,
    serialization_alias: str | None = _Unset,
    title: str | None = _Unset,
    field_title_generator: Callable[[str, FieldInfo], str] | None = _Unset,
    description: str | None = _Unset,
    examples: list[Any] | None = _Unset,
    exclude: bool | None = _Unset,
    discriminator: str | types.Discriminator | None = _Unset,
    deprecated: Deprecated | str | bool | None = _Unset,
    json_schema_extra: JsonDict | Callable[[JsonDict], None] | None = _Unset,
    frozen: bool | None = _Unset,
    validate_default: bool | None = _Unset,
    repr: bool = _Unset,
    init: bool | None = _Unset,
    init_var: bool | None = _Unset,
    kw_only: bool | None = _Unset,
    pattern: str | typing.Pattern[str] | None = _Unset,
    strict: bool | None = _Unset,
    coerce_numbers_to_str: bool | None = _Unset,
    gt: annotated_types.SupportsGt | None = _Unset,
    ge: annotated_types.SupportsGe | None = _Unset,
    lt: annotated_types.SupportsLt | None = _Unset,
    le: annotated_types.SupportsLe | None = _Unset,
    multiple_of: float | None = _Unset,
    allow_inf_nan: bool | None = _Unset,
    max_digits: int | None = _Unset,
    decimal_places: int | None = _Unset,
    min_length: int | None = _Unset,
    max_length: int | None = _Unset,
    union_mode: Literal['smart', 'left_to_right'] = _Unset,
    fail_fast: bool | None = _Unset,
    extra: Unpack[_EmptyKwargs] = {},
) -> _T
def PydanticModelField(
    alias: str | None = _Unset,
    alias_priority: int | None = _Unset,
    validation_alias: str | AliasPath | AliasChoices | None = _Unset,
    serialization_alias: str | None = _Unset,
    title: str | None = _Unset,
    field_title_generator: Callable[[str, FieldInfo], str] | None = _Unset,
    description: str | None = _Unset,
    examples: list[Any] | None = _Unset,
    exclude: bool | None = _Unset,
    discriminator: str | types.Discriminator | None = _Unset,
    deprecated: Deprecated | str | bool | None = _Unset,
    json_schema_extra: JsonDict | Callable[[JsonDict], None] | None = _Unset,
    frozen: bool | None = _Unset,
    validate_default: bool | None = _Unset,
    repr: bool = _Unset,
    init: bool | None = _Unset,
    init_var: bool | None = _Unset,
    kw_only: bool | None = _Unset,
    pattern: str | typing.Pattern[str] | None = _Unset,
    strict: bool | None = _Unset,
    coerce_numbers_to_str: bool | None = _Unset,
    gt: annotated_types.SupportsGt | None = _Unset,
    ge: annotated_types.SupportsGe | None = _Unset,
    lt: annotated_types.SupportsLt | None = _Unset,
    le: annotated_types.SupportsLe | None = _Unset,
    multiple_of: float | None = _Unset,
    allow_inf_nan: bool | None = _Unset,
    max_digits: int | None = _Unset,
    decimal_places: int | None = _Unset,
    min_length: int | None = _Unset,
    max_length: int | None = _Unset,
    union_mode: Literal['smart', 'left_to_right'] = _Unset,
    fail_fast: bool | None = _Unset,
    extra: Unpack[_EmptyKwargs] = {},
) -> Any

Usage docs: https://docs.pydantic.dev/2.10/concepts/fields

Create a field for objects that can be configured.

Used to provide extra information about a field, either for the model schema or complex validation. Some arguments apply only to number fields (int, float, Decimal) and some apply only to str.

Returns

Any — A new FieldInfo. The return annotation is Any so Field can be used on type-annotated fields without causing a type error.

Parameters

default : Any Default: PydanticUndefined

Default value if the field is not set.

default_factory : Callable[[], Any] | Callable[[dict[str, Any]], Any] | None Default: _Unset

A callable to generate the default value. The callable can either take 0 arguments (in which case it is called as is) or a single argument containing the already validated data.

alias : str | None Default: _Unset

The name to use for the attribute when validating or serializing by alias. This is often used for things like converting between snake and camel case.

alias_priority : int | None Default: _Unset

Priority of the alias. This affects whether an alias generator is used.

validation_alias : str | AliasPath | AliasChoices | None Default: _Unset

Like alias, but only affects validation, not serialization.

serialization_alias : str | None Default: _Unset

Like alias, but only affects serialization, not validation.

title : str | None Default: _Unset

Human-readable title.

field_title_generator : Callable[[str, FieldInfo], str] | None Default: _Unset

A callable that takes a field name and returns title for it.

description : str | None Default: _Unset

Human-readable description.

examples : list[Any] | None Default: _Unset

Example values for this field.

exclude : bool | None Default: _Unset

Whether to exclude the field from the model serialization.

discriminator : str | types.Discriminator | None Default: _Unset

Field name or Discriminator for discriminating the type in a tagged union.

deprecated : Deprecated | str | bool | None Default: _Unset

A deprecation message, an instance of warnings.deprecated or the typing_extensions.deprecated backport, or a boolean. If True, a default deprecation message will be emitted when accessing the field.

json_schema_extra : JsonDict | Callable[[JsonDict], None] | None Default: _Unset

A dict or callable to provide extra JSON schema properties.

frozen : bool | None Default: _Unset

Whether the field is frozen. If true, attempts to change the value on an instance will raise an error.

validate_default : bool | None Default: _Unset

If True, apply validation to the default value every time you create an instance. Otherwise, for performance reasons, the default value of the field is trusted and not validated.

repr : bool Default: _Unset

A boolean indicating whether to include the field in the __repr__ output.

init : bool | None Default: _Unset

Whether the field should be included in the constructor of the dataclass. (Only applies to dataclasses.)

init_var : bool | None Default: _Unset

Whether the field should only be included in the constructor of the dataclass. (Only applies to dataclasses.)

kw_only : bool | None Default: _Unset

Whether the field should be a keyword-only argument in the constructor of the dataclass. (Only applies to dataclasses.)

coerce_numbers_to_str : bool | None Default: _Unset

Whether to enable coercion of any Number type to str (not applicable in strict mode).

strict : bool | None Default: _Unset

If True, strict validation is applied to the field. See Strict Mode for details.

gt : annotated_types.SupportsGt | None Default: _Unset

Greater than. If set, value must be greater than this. Only applicable to numbers.

ge : annotated_types.SupportsGe | None Default: _Unset

Greater than or equal. If set, value must be greater than or equal to this. Only applicable to numbers.

lt : annotated_types.SupportsLt | None Default: _Unset

Less than. If set, value must be less than this. Only applicable to numbers.

le : annotated_types.SupportsLe | None Default: _Unset

Less than or equal. If set, value must be less than or equal to this. Only applicable to numbers.

multiple_of : float | None Default: _Unset

Value must be a multiple of this. Only applicable to numbers.

min_length : int | None Default: _Unset

Minimum length for iterables.

max_length : int | None Default: _Unset

Maximum length for iterables.

pattern : str | typing.Pattern[str] | None Default: _Unset

Pattern for strings (a regular expression).

allow_inf_nan : bool | None Default: _Unset

Allow inf, -inf, nan. Only applicable to numbers.

max_digits : int | None Default: _Unset

Maximum number of allow digits for strings.

decimal_places : int | None Default: _Unset

Maximum number of decimal places allowed for numbers.

union_mode : Literal['smart', 'left_to_right'] Default: _Unset

The strategy to apply when validating a union. Can be smart (the default), or left_to_right. See Union Mode for details.

fail_fast : bool | None Default: _Unset

If True, validation will stop on the first error. If False, all validation errors will be collected. This option can be applied only to iterable types (list, tuple, set, and frozenset).

extra : Unpack[_EmptyKwargs] Default: \{\}

(Deprecated) Extra fields that will be included in the JSON schema.


PydanticModelPrivateAttr

def PydanticModelPrivateAttr(default: _T, init: Literal[False] = False) -> _T
def PydanticModelPrivateAttr(
    default_factory: Callable[[], _T],
    init: Literal[False] = False,
) -> _T
def PydanticModelPrivateAttr(init: Literal[False] = False) -> Any

Usage docs: https://docs.pydantic.dev/2.10/concepts/models/#private-model-attributes

Indicates that an attribute is intended for private use and not handled during normal validation/serialization.

Private attributes are not validated by Pydantic, so it’s up to you to ensure they are used in a type-safe manner.

Private attributes are stored in __private_attributes__ on the model.

Returns

Any — An instance of ModelPrivateAttr class.

Parameters

default : Any Default: PydanticUndefined

The attribute’s default value. Defaults to Undefined.

default_factory : Callable[[], Any] | None Default: None

Callable that will be called when a default value is needed for this attribute. If both default and default_factory are set, an error will be raised.

init : Literal[False] Default: False

Whether the attribute should be included in the constructor of the dataclass. Always False.

Raises

  • ValueError — If both default and default_factory are set.

RootModelRootType

Default: typing.TypeVar('RootModelRootType')