It is assumed that ORM mode
supports arbitrary classes, not just databases ORM (it is named so because it is usually used in conjunction with it). More detailed here.
Example with regular class:
from pydantic import BaseModel
class SomeClass:
def __init__(self):
self.id = 100
self.name = "some_name"
class SomeModel(BaseModel):
id: int
name: str
class Config:
orm_mode = True
print(SomeModel.from_orm(SomeClass())) # id=100 name='some_name'
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…