Where possible Pydantic uses standard library types to define fields, thus smoothing the learning curve. For many useful applications, however, no standard library type exists, so Pydantic implements many commonly used types.
There are also more complex types that can be found in the Pydantic Extra Types.
If no existing type suits your purpose you can also implement your own Pydantic-compatible types with custom properties and validation.
The following sections describe the types supported by Pydantic.
- Standard Library Types — types from the Python standard library.
- Booleans —
- ByteSize — a type that allows handling byte string representations in your model.
- Callables —
- Datetimes —
- Dicts and Mapping Types —
dicttypes and mapping types.
- Enums and Choices — uses Python's standard
enumclasses to define choices.
- File Types — types for handling files and paths.
- JSON — a type that allows you to store JSON data in your model.
- Lists and Tuples —
- Number Types —
Decimal, and other number types.
- Secret Types — types for storing sensitive information that you do not want to be visible in logging or tracebacks.
- Sequence, Iterable, & Iterator — iterable types including
- Sets and frozenset —
- Strict Types — types that enable you to prevent coercion from compatible types.
- String Types —
- Type and TypeVar —
- Types with Fields — types that allow you to define fields.
- Unions — allows a model attribute to accept different types.
- URLs — URI/URL validation types.
- UUIDs — types that allow you to store UUIDs in your model.
- Base64 and other encodings — types that allow serializing values into an encoded form, e.g.
- Custom Data Types — create your own custom data types.
- Field Type Conversions — strict and lax conversion between different field types.
- Extra Types: Types that can be found in the optional Pydantic Extra Types package. These include:
- Color Types — types that enable you to store RGB color values in your model.
- Payment Card Numbers — types that enable you to store payment cards such as debit or credit cards.
- Phone Numbers — types that enable you to store phone numbers in your model.
- Routing Numbers — types that enable you to store ABA routing transit numbers in your model.