from pydantic import BaseModel from pydantic.alias_generators import to_camel class CustomConfig: populate_by_name = True from_attributes = True class CustomModelCamel(BaseModel): class Config: from_attributes = True alias_generator = to_camel populate_by_name = True @classmethod def from_sql_model(cls, model, fields: dict): model_dict = {c.name: getattr(model, c.name) for c in model.__table__.columns} model_dict.update(fields) return cls(**model_dict) class CustomModelSnake(BaseModel): class Config: from_attributes = True class OkMessageSchema(CustomModelCamel): ok: bool message: str class PaginationSchema(CustomModelCamel): page: int items_per_page: int class PaginationInfoSchema(CustomModelCamel): total_pages: int total_items: int