gsinha gsinha - 1 year ago 142
Python Question

Get list of all NDB model names ( class names ) in GAE Python

How to get the list of all NDB model names in GAE Python ?

All NDB models are Python classes which inherit from

. I thought we could use this info to fetch the names of all models.

class BK (ndb.Model):
property_1 = ..

I tried below ( borrowed ) code but in vain :

ATTEMPT 1 ( [ cls.__name__ for cls in globals()['ndb.Model'].__subclasses__() ] )

It results in error :

KeyError: 'ndb.Model'

ATTEMPT 2 ( [ cls.__name__ for cls in globals()['Model'].__subclasses__() ] )

It results in error :

KeyError: 'Model'

Answer Source

Fortunately for you, it is far easier in this case:

from google.appengine.ext import ndb

class Test(ndb.Model):

print ndb.Model._kind_map

Produces the following output:

{'Test': Test<>}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download