This solution seemed like it would help solve my problem: Getting attributes of a class
However, when I follow the steps linked above, my project only returns Config
and fields
. This is likely because these classes inherit from Pydantic's BaseModel
.
What I'm looking for is for a class, say:
class GameStatistics(BaseModel):
id: UUID
status: str
scheduled: datetime
I should return id
, status
, and scheduled
.
My attempt:
for name, cls in inspect.getmembers(module, lambda member: inspect.isclass(member) and member.__module__== module.__name__):
for _name, attrbs in inspect.getmembers(cls, lambda member: not(inspect.isroutine(member))):
if not _name.startswith('_'):
print(_name, attrbs)