OneBite.Dev - Coding blog in a bite size

How to add multiple types in pydantic

To allow pydantic to accept multiple values we can use Union

To allow pydantic to accept multiple values we can use Union and put the values inside the square brackets

For example:

favicon_link: Union[str, bool]

This way we allow favicon_link to be any str or bool

python