pydantic.config
Configuration for Pydantic models.
BaseConfig ¶
This class is only retained for backwards compatibility.
Deprecated
BaseConfig is deprecated. Use the pydantic.ConfigDict
instead.
ConfigDict ¶
Bases: TypedDict
A dictionary-like class for configuring Pydantic models.
Attributes:
Name | Type | Description |
---|---|---|
title |
str | None
|
The title for the generated JSON schema. Defaults to |
str_to_lower |
bool
|
Whether to convert all characters to lowercase for str & bytes types. Defaults to |
str_to_upper |
bool
|
Whether to convert all characters to uppercase for str & bytes types. Defaults to |
str_strip_whitespace |
bool
|
Whether to strip leading and trailing whitespace for str & bytes types.
Defaults to |
str_min_length |
int
|
The minimum length for str & bytes types. Defaults to |
str_max_length |
int | None
|
The maximum length for str & bytes types. Defaults to |
extra |
ExtraValues | None
|
Whether to ignore, allow, or forbid extra attributes during model initialization.
Accepts the string values of
See Extra Attributes for details. |
frozen |
bool
|
Whether or not models are faux-immutable, i.e. whether Note On V1, this setting was called |
populate_by_name |
bool
|
Whether an aliased field may be populated by its name as given by the model
attribute, as well as the alias. Defaults to Note The name of this configuration setting was changed in v2.0 from
|
use_enum_values |
bool
|
Whether to populate models with the |
validate_assignment |
bool
|
Whether to perform validation on assignment to attributes. Defaults to |
arbitrary_types_allowed |
bool
|
Whether to allow arbitrary user types for fields (they are validated simply by
checking if the value is an instance of the type). If See Arbitrary Types Allowed for details. |
from_attributes |
bool
|
Whether to allow model creation from object attributes. Defaults to Note The name of this configuration setting was changed in v2.0 from |
loc_by_alias |
bool
|
Whether to use the alias for error |
alias_generator |
Callable[[str], str] | None
|
a callable that takes a field name and returns an alias for it. See Alias Generator for details. |
ignored_types |
tuple[type, ...]
|
A tuple of types that may occur as values of class attributes without annotations. This is
typically used for custom descriptors (classes that behave like |
allow_inf_nan |
bool
|
Whether to allow infinity ( |
json_schema_extra |
dict[str, object] | JsonSchemaExtraCallable | None
|
A dict or callable to provide extra JSON schema properties. Defaults to |
strict |
bool
|
If |
revalidate_instances |
Literal['always', 'never', 'subclass-instances']
|
When and how to revalidate models and dataclasses during validation. Accepts the string
values of
See Revalidate Instances for details. |
ser_json_timedelta |
Literal['iso8601', 'float']
|
The format of JSON serialized timedeltas. Accepts the string values of
|
ser_json_bytes |
Literal['utf8', 'base64']
|
The encoding of JSON serialized bytes. Accepts the string values of
|
validate_default |
bool
|
Whether to validate default values during validation. Defaults to |
protected_namespaces |
tuple[str, ...]
|
A See Protected Namespaces for details. |
hide_input_in_errors |
bool
|
Whether to hide inputs when printing errors. Defaults to See Hide Input in Errors. |