How to list all entity kinds programmatically?

344 views
Skip to first unread message

Trung

unread,
Mar 24, 2010, 8:46:19 PM3/24/10
to Google App Engine
Hi,

I'd like to know whether we can programmatically know the list of
entity
KIND currently in the datastore.

Thanks in advance.

mstodd

unread,
Mar 25, 2010, 3:19:20 PM3/25/10
to Google App Engine
Well, the admin interface can list them, so I tracked down how that's
happening, and it's in google/google_appengine/google/appengine/ext/
admin/__init__.py

check out get_kinds() in that file.
looks like it just uses datastore_admin from google.appengine.api

let me know if you get stuck.

kostmo

unread,
Mar 29, 2010, 7:12:53 PM3/29/10
to Google App Engine
I tried to use the body of the get_kinds() function (after adding the
line "from google.appengine.api import datastore_admin"), but I get
the error:

BadRequestError: app [myappname] cannot call GetSchema

Karl


On Mar 25, 2:19 pm, mstodd <toaste...@gmail.com> wrote:
> Well, the admin interface canlistthem, so I tracked down how that's

kostmo

unread,
Mar 29, 2010, 7:28:49 PM3/29/10
to Google App Engine
Update:
I found success adapting the body of GetSchemaKinds() from
bulkloader.py:

def GetSchemaKinds(self):
"""Returns the list of kinds for this app."""

class KindStatError(Exception):
"""Unable to find kind stats for an all-kinds download."""

from google.appengine.ext.db import stats
global_stat = stats.GlobalStat.all().get()
if not global_stat:
raise KindStatError()
timestamp = global_stat.timestamp
kind_stat = stats.KindStat.all().filter(
"timestamp =", timestamp).fetch(1000)
kind_list = [stat.kind_name for stat in kind_stat
if stat.kind_name and not
stat.kind_name.startswith('__')]
kind_set = set(kind_list)
return list(kind_set)

Reply all
Reply to author
Forward
0 new messages