Custom Data Types & Settings
Define custom Pydantic data types and manage application settings using Pydantic's `BaseSettings`.
Welcome to Custom Types!
Pydantic is great for validating data, but sometimes you need validation beyond its built-in types.
- Custom Data Types let you define your own rules for data.
- This ensures your data adheres to specific formats or business logic.
- Think of it as extending Pydantic's power for unique needs.
`Annotated` for Custom Validation
Pydantic v2 uses Python's typing.Annotated alongside validator functions to create custom types.
Annotated: Adds metadata to a type hint.BeforeValidator: Runs a function before Pydantic's standard validation.- This allows you to transform or validate input data before it's assigned.