Clearing Entries in App Engine – Clearing the Data Store

It would be nice to have bulk clear of the App Engine Data Store. Many folks have resorted to little REST like ways to do this. Here is my take on it:

class PurgeHandler(webapp.RequestHandler):
def get(self):
if not users.is_current_user_admin() :
self.response.out.write('Must be admin.')
return
limit = self.request.get("limit")
if not limit:
limit = 10
table = self.request.get('table')
if not table:
self.response.out.write('Must specify a table.')
return
q = db.GqlQuery("SELECT __key__ FROM "+table)
results = q.fetch(10)
self.response.out.write("%s records" % len(results))
db.delete(results)

Nothing fancy. This could easily be improved and I may improve it after I get some free time.

Reference: I got my inspiration from this Google Groups Post