How can I find all hybrid attributes of a SQLAlchemy model?

I need to find a way to get a list of all hybrid properties of SQLAlchemy models.

For relationships in a Person instance, I can do something like:

from sqlalchemy.inspection import inspect
inspect(person.__class__).relationships 

      

Is there something like:

 inspect(person.__class__).hybrid_properties

      

+3


source to share


1 answer


Here is the solution I came up with:



from sqlalchemy.inspection import inspect as sa_inspect
from sqlalchemy.ext.hybrid import hybrid_property

for item in sa_inspect(A_MODEL_INSTANCE.__class__).all_orm_descriptors:
    if type(item) == hybrid_property:
        print item.__name__

      

+3


source







All Articles