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

Conversion Table

The following table provides details on how Pydantic converts data during validation in both strict and lax modes.

The “Strict” column contains checkmarks for type conversions that are allowed when validating in Strict Mode.

Field TypeInputStrictInput SourceConditions
boolbool✓Python & JSON
boolbytesPythonSame allowed values as for str. Assumes UTF-8.
boolfloatPython & JSONAllowed values: 0.0, 1.0.
boolintPython & JSONAllowed values: 0, 1.
boolstrPython & JSONCase-insensitive. Allowed values: '0', 'off', 'f', 'false', 'n', 'no', '1', 'on', 't', 'true', 'y', 'yes'.
boolDecimalPythonAllowed values: Decimal(0), Decimal(1).
bytesbytearrayPython
bytesbytes✓Python
bytesstr✓JSONDecoded according to the val_json_bytes setting (UTF-8 by default).
bytesstrPythonDecoded according to the val_json_bytes setting (UTF-8 by default).
callable-JSONNever valid.
callableAny✓Pythoncallable() check must return True.
complexcomplex✓Python
complexfloatPython & JSON
complexintPython & JSON
complexstr✓JSONMust be a valid complex string, e.g. 1+2j.
complexstrPythonMust be a valid complex string, e.g. 1+2j.
complexDecimalPython
datebytesPythonFormat: YYYY-MM-DD, a datetime with a zero time component, or a unix timestamp. Must be exact date. See speedate. Assumes UTF-8.
datedate✓Python
datedatetimePythonMust be exact date, eg. no H, M, S, f.
datefloatPython & JSONInterpreted as seconds or milliseconds from epoch, depending on the val_temporal_unit setting. Must be exact date.
dateintPython & JSONInterpreted as seconds or milliseconds from epoch, depending on the val_temporal_unit setting. Must be exact date.
datestr✓JSONFormat: YYYY-MM-DD, or a unix timestamp. Must be exact date.
datestrPython & JSONFormat: YYYY-MM-DD, a datetime with a zero time component, or a unix timestamp. Must be exact date. See speedate.
dateDecimalPythonInterpreted as seconds or milliseconds from epoch, depending on the val_temporal_unit setting. Must be exact date.
datetimebytesPythonFormat: YYYY-MM-DDTHH:MM:SS.f, YYYY-MM-DD, or a unix timestamp. See speedate. Assumes UTF-8.
datetimedatePython
datetimedatetime✓Python
datetimefloatPython & JSONInterpreted as seconds or milliseconds from epoch, depending on the val_temporal_unit setting.
datetimeintPython & JSONInterpreted as seconds or milliseconds from epoch, depending on the val_temporal_unit setting.
datetimestr✓JSONFormat: YYYY-MM-DDTHH:MM:SS.f, or a unix timestamp. See speedate.
datetimestrPython & JSONFormat: YYYY-MM-DDTHH:MM:SS.f, YYYY-MM-DD, or a unix timestamp. See speedate.
datetimeDecimalPythonInterpreted as seconds or milliseconds from epoch, depending on the val_temporal_unit setting.
dequedeque✓Python
dequefrozensetPython
dequelistPython
dequesetPython
dequetuplePython
dequeArray✓JSON
dequeIterablePythonAny iterable except str, bytes, bytearray, dict and mappings, e.g. generators.
dictdict✓Python
dictMappingPythonMust implement the mapping interface and have an items() method.
dictObject✓JSON
floatboolPython & JSON
floatbytesPythonMust be a valid float, e.g. 3.141, 1e3 or inf. Leading and trailing whitespace and underscores are allowed. Assumes UTF-8.
floatfloat✓Python & JSONbool is explicitly forbidden.
floatint✓Python & JSON
floatstrPython & JSONMust be a valid float, e.g. 3.141, 1e3 or inf. Leading and trailing whitespace and underscores are allowed.
floatAny✓PythonMust implement __float__() or __index__().
floatDecimal✓Python
floatFraction✓Python
frozendictdictPythonfrozendict is only available in Python 3.15 and above.
frozendictfrozendict✓Pythonfrozendict is only available in Python 3.15 and above.
frozendictMappingPythonfrozendict is only available in Python 3.15 and above. The input must implement the mapping interface and have an items() method.
frozendictObject✓JSONfrozendict is only available in Python 3.15 and above.
frozensetdequePython
frozensetdict_keysPython
frozensetdict_valuesPython
frozensetfrozenset✓Python
frozensetlistPython
frozensetsetPython
frozensettuplePython
frozensetArray✓JSON
frozensetIterablePythonAny iterable except str, bytes, bytearray, dict and mappings, e.g. generators.
intboolPython & JSON
intbytesPythonMust be a valid integer, e.g. 123. Leading and trailing whitespace, underscores and a zero fractional part (e.g. 1.0) are allowed. Assumes UTF-8.
intfloatPython & JSONMust be exact int, e.g. val % 1 == 0, raises error for nan, inf.
intint✓Python & JSONbool is explicitly forbidden.
intstrPython & JSONMust be a valid integer, e.g. 123. Leading and trailing whitespace, underscores and a zero fractional part (e.g. 1.0) are allowed.
intDecimalPythonMust be exact int, e.g. val % 1 == 0.
intEnumPythonUses the value of the enum member.
intFractionPythonMust be exact int, e.g. val % 1 == 0.
listdequePython
listdict_keysPython
listdict_valuesPython
listfrozensetPython
listlist✓Python
listsetPython
listtuplePython
listArray✓JSON
listIterablePythonAny iterable except str, bytes, bytearray, dict and mappings, e.g. generators.
namedtupledict✓Python
namedtuplelist✓Python
namedtuplenamedtuple✓Python
namedtupletuple✓Python
namedtupleArray✓JSON
namedtupleIterable✓PythonAny iterable except str, bytes, bytearray, dict and mappings, e.g. generators.
namedtupleMapping✓PythonMust implement the mapping interface and have an items() method.
namedtupleNamedTuple✓Python
namedtupleObject✓JSON
setdequePython
setdict_keysPython
setdict_valuesPython
setfrozensetPython
setlistPython
setset✓Python
settuplePython
setArray✓JSON
setIterablePythonAny iterable except str, bytes, bytearray, dict and mappings, e.g. generators.
strbytearrayPythonAssumes UTF-8, error on unicode decoding error.
strbytesPythonAssumes UTF-8, error on unicode decoding error.
strfloatPython & JSONOnly if coerce_numbers_to_str is enabled.
strintPython & JSONOnly if coerce_numbers_to_str is enabled.
strstr✓Python & JSON
strDecimalPythonOnly if coerce_numbers_to_str is enabled.
strEnumPythonUses the value of the enum member.
timebytesPythonFormat: HH:MM[:SS[.FFFFFF]], with an optional timezone offset. See speedate. Assumes UTF-8.
timefloatPython & JSONInterpreted as seconds, range 0 - 86399.9*.
timeintPython & JSONInterpreted as seconds, range 0 - 86399.
timestr✓JSONFormat: HH:MM[:SS[.FFFFFF]], with an optional timezone offset. See speedate.
timestrPython & JSONFormat: HH:MM[:SS[.FFFFFF]], with an optional timezone offset. See speedate.
timetime✓Python
timeDecimalPythonInterpreted as seconds, range 0 - 86399.9*.
timedeltabytesPythonFormat: ISO8601. See speedate, (UTF-8).
timedeltafloatPython & JSONInterpreted as seconds.
timedeltaintPython & JSONInterpreted as seconds.
timedeltastr✓JSONFormat: ISO8601. See speedate.
timedeltastrPython & JSONFormat: ISO8601. See speedate.
timedeltatimedelta✓Python
timedeltaDecimalPythonInterpreted as seconds.
tupledequePython
tupledict_keysPython
tupledict_valuesPython
tuplefrozensetPython
tuplelistPython
tuplesetPython
tupletuple✓Python
tupleArray✓JSON
tupleIterablePythonAny iterable except str, bytes, bytearray, dict and mappings, e.g. generators.
type-JSONNever valid.
typetype✓Python
AnyAny✓Python & JSON
ByteSizefloatPython & JSONMust be exact int, e.g. val % 1 == 0.
ByteSizeint✓Python & JSON
ByteSizestr✓Python & JSON
ByteSizeDecimalPythonMust be exact int, e.g. val % 1 == 0.
CounterdictPython
CounterCounter✓Python
CounterMappingPythonMust implement the mapping interface and have an items() method.
CounterObject✓JSON
Decimalfloat✓JSON
DecimalfloatPython & JSON
Decimalint✓JSON
DecimalintPython & JSON
Decimalstr✓JSON
DecimalstrPython & JSONMust be a valid decimal, e.g. 3.141 or 1e3. Leading and trailing whitespace and underscores are allowed.
DecimaltuplePythonDecimal tuple form, e.g. (0, (1, 4, 1), -2).
DecimalDecimal✓Python
EnumAny✓JSONInput value must be convertible to enum values.
EnumAnyPythonInput value must be convertible to enum values.
EnumEnum✓Python
Fractionfloat✓JSON
FractionfloatPython
Fractionint✓JSON
FractionintPython
Fractionstr✓JSONMust be a valid fraction, e.g. 1/3 or 0.5.
FractionstrPythonMust be a valid fraction, e.g. 1/3 or 0.5.
FractionDecimalPython
FractionFraction✓Python
HashableAny✓Python & JSONisinstance() check against Hashable must return True.
IPv4AddressbytesPython
IPv4AddressintPython & JSONinteger representing the IP address, must be less than 2**32
IPv4Addressstr✓JSON
IPv4AddressstrPython & JSON
IPv4AddressIPv4Address✓Python
IPv4AddressIPv4Interface✓Python
IPv4InterfacebytesPython
IPv4InterfaceintPython & JSONinteger representing the IP address, must be less than 2**32
IPv4Interfacestr✓JSON
IPv4InterfacestrPython & JSON
IPv4InterfacetuplePython
IPv4InterfaceIPv4AddressPython
IPv4InterfaceIPv4Interface✓Python
IPv4InterfaceIPv4NetworkPython
IPv4NetworkbytesPython
IPv4NetworkintPython & JSONinteger representing the IP network, must be less than 2**32
IPv4Networkstr✓JSONHost bits must be zero.
IPv4NetworkstrPython & JSONHost bits must be zero.
IPv4NetworktuplePythonHost bits must be zero.
IPv4NetworkIPv4AddressPython
IPv4NetworkIPv4InterfacePythonHost bits must be zero.
IPv4NetworkIPv4Network✓Python
IPv6AddressbytesPython
IPv6AddressintPython & JSONinteger representing the IP address, must be less than 2**128
IPv6Addressstr✓JSON
IPv6AddressstrPython & JSON
IPv6AddressIPv6Address✓Python
IPv6AddressIPv6Interface✓Python
IPv6InterfacebytesPython
IPv6InterfaceintPython & JSONinteger representing the IP address, must be less than 2**128
IPv6Interfacestr✓JSON
IPv6InterfacestrPython & JSON
IPv6InterfacetuplePython
IPv6InterfaceIPv6AddressPython
IPv6InterfaceIPv6Interface✓Python
IPv6InterfaceIPv6NetworkPython
IPv6NetworkbytesPython
IPv6NetworkintPython & JSONinteger representing the IP address, must be less than 2**128
IPv6Networkstr✓JSONHost bits must be zero.
IPv6NetworkstrPython & JSONHost bits must be zero.
IPv6NetworktuplePythonHost bits must be zero.
IPv6NetworkIPv6AddressPython
IPv6NetworkIPv6InterfacePythonHost bits must be zero.
IPv6NetworkIPv6Network✓Python
InstanceOfAny✓JSONValidated as the wrapped type.
InstanceOfAny✓Pythonisinstance() check must return True.
IntEnumAny✓JSONInput value must be one of the enum values, without type coercion.
IntEnumAnyPythonInput value must be convertible to enum values.
IntEnumIntEnum✓Python
IterableAny✓PythonAny object for which iter() succeeds. Items are validated lazily.
IterableArray✓JSON
LiteralAny✓Python & JSONInput must be equal to one of the literal values.
NamedTupledict✓Python
NamedTuplelist✓Python
NamedTuplenamedtuple✓Python
NamedTupletuple✓Python
NamedTupleArray✓JSON
NamedTupleIterable✓PythonAny iterable except str, bytes, bytearray, dict and mappings, e.g. generators.
NamedTupleMapping✓PythonMust implement the mapping interface and have an items() method.
NamedTupleNamedTuple✓Python
NamedTupleObject✓JSON
NoneNone✓Python & JSON
OrderedDictdictPython
OrderedDictMappingPythonMust implement the mapping interface and have an items() method.
OrderedDictObject✓JSON
OrderedDictOrderedDict✓Python
Pathstr✓JSON
PathstrPython
PathPath✓Python
Patternbytes✓PythonInput must be a valid pattern. Not valid for Pattern[str].
Patternstr✓Python & JSONInput must be a valid pattern. Not valid for Pattern[bytes].
PatternPattern✓PythonThe pattern type (str or bytes) must match.
SequencedequePython
Sequencelist✓Python
Sequencetuple✓Python
SequenceArray✓JSON
TypedDictdict✓Python
TypedDictMappingPythonMust implement the mapping interface and have an items() method.
TypedDictObject✓JSON
UUIDbytesPython16 raw bytes, or a UTF-8 encoded UUID string.
UUIDstr✓JSON
UUIDstrPython
UUIDUUID✓Python