Skip to content
You're viewing docs for v2.8. 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
boolboolPython & JSON
boolfloatPython & JSONAllowed values: 0.0, 1.0.
boolintPython & JSONAllowed values: 0, 1.
boolstrPython & JSONAllowed values: 'f', 'n', 'no', 'off', 'false', 'False', 't', 'y', 'on', 'yes', 'true', 'True'.
boolDecimalPythonAllowed values: Decimal(0), Decimal(1).
bytesbytearrayPython
bytesbytesPython
bytesstrJSON
bytesstrPython
callable-JSONNever valid.
callableAnyPythoncallable() check must return True.
datebytesPythonFormat: YYYY-MM-DD (UTF-8).
datedatePython
datedatetimePythonMust be exact date, eg. no H, M, S, f.
datefloatPython & JSONInterpreted as seconds or ms from epoch. See speedate. Must be exact date.
dateintPython & JSONInterpreted as seconds or ms from epoch. See speedate. Must be exact date.
datestrPython & JSONFormat: YYYY-MM-DD.
dateDecimalPythonInterpreted as seconds or ms from epoch. See speedate. Must be exact date.
datetimebytesPythonFormat: YYYY-MM-DDTHH:MM:SS.f or YYYY-MM-DD. See speedate, (UTF-8).
datetimedatePython
datetimedatetimePython
datetimefloatPython & JSONInterpreted as seconds or ms from epoch, see speedate.
datetimeintPython & JSONInterpreted as seconds or ms from epoch, see speedate.
datetimestrPython & JSONFormat: YYYY-MM-DDTHH:MM:SS.f or YYYY-MM-DD. See speedate.
datetimeDecimalPythonInterpreted as seconds or ms from epoch, see speedate.
dequedequePython
dequefrozensetPython
dequelistPython
dequesetPython
dequetuplePython
dequeArrayJSON
dictdictPython
dictMappingPythonMust implement the mapping interface and have an items() method.
dictObjectJSON
floatboolPython & JSON
floatbytesPythonMust match [0-9]+(\.[0-9]+)?.
floatfloatPython & JSONbool is explicitly forbidden.
floatintPython & JSON
floatstrPython & JSONMust match [0-9]+(\.[0-9]+)?.
floatDecimalPython
frozensetdequePython
frozensetdict_keysPython
frozensetdict_valuesPython
frozensetfrozensetPython
frozensetlistPython
frozensetsetPython
frozensettuplePython
frozensetArrayJSON
intboolPython & JSON
intbytesPythonMust be numeric only, e.g. [0-9]+.
intfloatPython & JSONMust be exact int, e.g. val % 1 == 0, raises error for nan, inf.
intintPython & JSONbool is explicitly forbidden.
intintPython & JSON
intstrPython & JSONMust be numeric only, e.g. [0-9]+.
intDecimalPythonMust be exact int, e.g. val % 1 == 0.
listdequePython
listdict_keysPython
listdict_valuesPython
listfrozensetPython
listlistPython
listsetPython
listtuplePython
listArrayJSON
namedtupledictPython
namedtuplelistPython
namedtuplenamedtuplePython
namedtupletuplePython
namedtupleArrayJSON
namedtupleNamedTuplePython
setdequePython
setdict_keysPython
setdict_valuesPython
setfrozensetPython
setlistPython
setsetPython
settuplePython
setArrayJSON
strbytearrayPythonAssumes UTF-8, error on unicode decoding error.
strbytesPythonAssumes UTF-8, error on unicode decoding error.
strstrPython & JSON
timebytesPythonFormat: HH:MM:SS.FFFFFF. See speedate.
timefloatPython & JSONInterpreted as seconds, range 0 - 86399.9*.
timeintPython & JSONInterpreted as seconds, range 0 - 86399.
timestrPython & JSONFormat: HH:MM:SS.FFFFFF. See speedate.
timetimePython
timeDecimalPythonInterpreted as seconds, range 0 - 86399.9*.
timedeltabytesPythonFormat: ISO8601. See speedate, (UTF-8).
timedeltafloatPython & JSONInterpreted as seconds.
timedeltaintPython & JSONInterpreted as seconds.
timedeltastrPython & JSONFormat: ISO8601. See speedate.
timedeltatimedeltaPython
timedeltaDecimalPythonInterpreted as seconds.
tupledequePython
tupledict_keysPython
tupledict_valuesPython
tuplefrozensetPython
tuplelistPython
tuplesetPython
tupletuplePython
tupleArrayJSON
AnyAnyPython & JSON
ByteSizefloatPython & JSON
ByteSizeintPython & JSON
ByteSizestrPython & JSON
ByteSizeDecimalPython
DecimalfloatJSON
DecimalfloatPython & JSON
DecimalintJSON
DecimalintPython & JSON
DecimalstrJSON
DecimalstrPython & JSONMust match [0-9]+(\.[0-9]+)?.
DecimalDecimalPython
EnumAnyJSONInput value must be convertible to enum values.
EnumAnyPythonInput value must be convertible to enum values.
EnumEnumPython
IPv4AddressbytesPython
IPv4AddressintPythoninteger representing the IP address, must be less than 2**32
IPv4AddressstrJSON
IPv4AddressstrPython & JSON
IPv4AddressIPv4AddressPython
IPv4AddressIPv4InterfacePython
IPv4InterfacebytesPython
IPv4InterfaceintPythoninteger representing the IP address, must be less than 2**32
IPv4InterfacestrJSON
IPv4InterfacestrPython & JSON
IPv4InterfacetuplePython
IPv4InterfaceIPv4AddressPython
IPv4InterfaceIPv4InterfacePython
IPv4NetworkbytesPython
IPv4NetworkintPythoninteger representing the IP network, must be less than 2**32
IPv4NetworkstrJSON
IPv4NetworkstrPython & JSON
IPv4NetworkIPv4AddressPython
IPv4NetworkIPv4InterfacePython
IPv4NetworkIPv4NetworkPython
IPv6AddressbytesPython
IPv6AddressintPythoninteger representing the IP address, must be less than 2**128
IPv6AddressstrJSON
IPv6AddressstrPython & JSON
IPv6AddressIPv6AddressPython
IPv6AddressIPv6InterfacePython
IPv6InterfacebytesPython
IPv6InterfaceintPythoninteger representing the IP address, must be less than 2**128
IPv6InterfacestrJSON
IPv6InterfacestrPython & JSON
IPv6InterfacetuplePython
IPv6InterfaceIPv6AddressPython
IPv6InterfaceIPv6InterfacePython
IPv6NetworkbytesPython
IPv6NetworkintPythoninteger representing the IP address, must be less than 2**128
IPv6NetworkstrJSON
IPv6NetworkstrPython & JSON
IPv6NetworkIPv6AddressPython
IPv6NetworkIPv6InterfacePython
IPv6NetworkIPv6NetworkPython
InstanceOf-JSONNever valid.
InstanceOfAnyPythonisinstance() check must return True.
IntEnumAnyJSONInput value must be convertible to enum values.
IntEnumAnyPythonInput value must be convertible to enum values.
IntEnumIntEnumPython
IterabledequePython
IterablefrozensetPython
IterablelistPython
IterablesetPython
IterabletuplePython
IterableArrayJSON
NamedTupledictPython
NamedTuplelistPython
NamedTuplenamedtuplePython
NamedTupletuplePython
NamedTupleArrayJSON
NamedTupleNamedTuplePython
NoneNonePython & JSON
PathstrJSON
PathstrPython
PathPathPython
PatternbytesPythonInput must be a valid pattern.
PatternstrPython & JSONInput must be a valid pattern.
SequencedequePython
SequencelistPython
SequencetuplePython
SequenceArrayJSON
TypeTypePython
TypedDictdictPython
TypedDictAnyPython
TypedDictMappingPythonMust implement the mapping interface and have an items() method.
TypedDictObjectJSON
UUIDstrJSON
UUIDstrPython
UUIDUUIDPython