Field() - all constraints
Fieldfrom pydantic import BaseModel, Field
from typing import Optional
class UserCreate(BaseModel):
username: str = Field(..., min_length=3, max_length=20)
email: str = Field(..., pattern=r"^[^@]+@[^@]+\.[^@]+$")
password: str = Field(..., min_length=8, exclude=True)
age: int = Field(..., ge=13, le=120)
bio: Optional[str] = Field(
None,
max_length=500,
title="Bio",
description="Short user biography",
examples=["Senior dev at RTE"]
)
score: float = Field(0.0, ge=0, le=100)
price: float = Field(..., gt=0, multiple_of=0.01)