Take the 2-minute tour ×

Does anyone know how to delete all datastore in Google App Engine?

share|improve this question
retag as google-datastore –  antony.trupe Sep 17 '09 at 18:01
db.delete(db.Query()) –  Andrey Gubarev May 10 '11 at 22:06
db.delete(db.Query(keys_only=True)). Further details here stackoverflow.com/a/10856555/290340. –  Evan Plaice Jun 1 '12 at 20:29
As pointed out by @systempuntoout below, GAE now has a Datastore Admin that lets you delete entities in bulk without any coding, among other things. That feature needs to be surfaced here rather than buried in the 3rd comment. –  ralfoide Dec 14 '12 at 21:32
The Datastore Admin doesn't work (the page loads an iframe to a non-existent host), so we'd still need to use the db.delete method. –  dpk Feb 10 '13 at 3:12

24 Answers 24

If you're talking about the live datastore, open the dashboard for your app (login on appengine) then datastore --> dataviewer, select all the rows for the table you want to delete and hit the delete button (you'll have to do this for all your tables). You can do the same programmatically through the remote_api (but I never used it).

If you're talking about the development datastore, you'll just have to delete the following file: "./WEB-INF/appengine-generated/local_db.bin". The file will be generated for you again next time you run the development server and you'll have a clear db.

Make sure to clean your project afterwards.

This is one of the little gotchas that come in handy when you start playing with the Google Application Engine. You'll find yourself persisting objects into the datastore then changing the JDO object model for your persistable entities ending up with a obsolete data that'll make your app crash all over the place.

share|improve this answer
I mean datastore in appengine server of google –  manman Jun 30 '09 at 8:57
There's a -c parameter to the dev_appserver.py to delete from the development datastore. –  svrist Sep 11 '09 at 8:49
@svrist But that only applies to the Python app engine. Does anybody know how a shortcut for doing it in Java? (In the meantime, JohnIdol's suggestion works well.) –  mgiuca Apr 29 '11 at 7:44

The best approach is the remote API method as suggested by Nick, he's an App Engine engineer from Google, so trust him.

It's not that difficult to do, and the latest 1.2.5 SDK provides the remote_shell_api.py out of the shelf. So go to download the new SDK. Then follow the steps:

  • connect remote server in your commandline: remote_api_shell.py yourapp /remote_api The shell will ask for your login info, and if authorized, will make a Python shell for you. You need setup url handler for /remote_api in your app.yaml

  • fetch the entities you'd like to delete, the code looks something like:

    from models import Entry
    query = Entry.all(keys_only=True)
    entries =query.fetch(1000)
    \# This could bulk delete 1000 entities a time

Update 2013-10-28:

  • remote_shell_api.py has been replaced by remote_api_shell.py, and you should connect with remote_api_shell.py -s your_app_id.appspot.com, according to the documentation.

  • There is a new experimental feature Datastore Admin, after enabling it in app settings, you can bulk delete as well as backup your datastore through the web ui.

share|improve this answer
Actually, you don't need the fetch. Just db.delete(Entry.all()) will do it. –  download Aug 23 '10 at 22:10
You need to do this in 500 entity sets or else you'll get: BadRequestError: cannot delete more than 500 entities in a single call –  marcc Oct 1 '10 at 1:43
Just an FYI, for you to use the remote api you need to enable it in your application first using builtins:- remote_api: in your YAML file. more info is at developers.google.com/appengine/articles/remote_api –  Zaffiro Aug 28 '12 at 13:23
At least add the 'keys_only=True' when you call Entry.all(). There's no need to fetch the whole entry if you don't need to check the data. Else you're just wasting computing cycles. –  Evan Plaice Sep 26 '12 at 21:53
Thanks Evan, I've added keys_only=True as you suggested. –  Juvenn Woo Sep 27 '12 at 6:35

The fastest and efficient way to handle bulk delete on Datastore is by using the new mapper API announced on the latest Google I/O.

If your language of choice is Python, you just have to register your mapper in a mapreduce.yaml file and define a function like this:

from mapreduce import operation as op
def process(entity):
 yield op.db.Delete(entity)

On Java you should have a look to this article that suggests a function like this:

public void map(Key key, Entity value, Context context) {
    log.info("Adding key to deletion pool: " + key);
    DatastoreMutationPool mutationPool = this.getAppEngineContext(context)

Since SDK 1.3.8, there's a Datastore admin feature for this purpose

share|improve this answer
Really impressive. Thank you. –  Guido García Sep 4 '10 at 16:46

You can clear the development server datastore when you run the server:

/path/to/dev_appserver.py --clear_datastore=yes myapp

You can also abbreviate --clear_datastore with -c.

share|improve this answer
You can also abbreviate "--clear_datastore" with "-c". –  Steven Almeroth Jun 27 '12 at 14:33
double bonus for less keystrokes ! –  nate_weldon Mar 4 '13 at 15:05
Not sure if it's a recent thing, but the actual syntax is now /path/to/google_appengine/dev_appserver.py --clear_datastore yes myappname/ (note the 'yes') –  Melllvar Aug 16 '13 at 16:05
Thanks @Melllvar, answer updated. –  Steven Almeroth Mar 18 at 17:59

If you have a significant amount of data, you need to use a script to delete it. You can use remote_api to clear the datastore from the client side in a straightforward manner, though.

share|improve this answer

Here you go: Go to Datastore Admin, and then select the Entity type you want to delete and click Delete. Mapreduce will take care of deleting!

share|improve this answer

The zero-setup way to do this is to send an execute-arbitrary-code HTTP request to the admin service that your running app already, automatically, has:

import urllib
import urllib2

    data = urllib.urlencode({'code' : 'from google.appengine.ext import db\n' +
share|improve this answer
Brilliant, exactly what I needed in my case. –  Mason Jun 27 '11 at 6:38
This only works for the development server. Is there a production equivalent? –  Gady Sep 10 '11 at 23:38


I got this from http://code.google.com/appengine/articles/remote_api.html.

Create the Interactive Console

First, you need to define an interactive appenginge console. So, create a file called appengine_console.py and enter this:

import code
import getpass
import sys

# These are for my OSX installation. Change it to match your google_appengine paths. sys.path.append("/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine")

from google.appengine.ext.remote_api import remote_api_stub
from google.appengine.ext import db

def auth_func():
  return raw_input('Username:'), getpass.getpass('Password:')

if len(sys.argv) < 2:
  print "Usage: %s app_id [host]" % (sys.argv[0],)
app_id = sys.argv[1]
if len(sys.argv) > 2:
  host = sys.argv[2]
  host = '%s.appspot.com' % app_id

remote_api_stub.ConfigureRemoteDatastore(app_id, '/remote_api', auth_func, host)

code.interact('App Engine interactive console for %s' % (app_id,), None, locals())

Create the Mapper base class

Once that's in place, create this Mapper class. I just created a new file called utils.py and threw this:

class Mapper(object):
  # Subclasses should replace this with a model class (eg, model.Person).
  KIND = None

  # Subclasses can replace this with a list of (property, value) tuples to filter by.
  FILTERS = []

  def map(self, entity):
    """Updates a single entity.

    Implementers should return a tuple containing two iterables (to_update, to_delete).
    return ([], [])

  def get_query(self):
    """Returns a query over the specified kind, with any appropriate filters applied."""
    q = self.KIND.all()
    for prop, value in self.FILTERS:
      q.filter("%s =" % prop, value)
    return q

  def run(self, batch_size=100):
    """Executes the map procedure over all matching entities."""
    q = self.get_query()
    entities = q.fetch(batch_size)
    while entities:
      to_put = []
      to_delete = []
      for entity in entities:
        map_updates, map_deletes = self.map(entity)
      if to_put:
      if to_delete:
      q = self.get_query()
      q.filter("__key__ >", entities[-1].key())
      entities = q.fetch(batch_size)

Mapper is supposed to be just an abstract class that allows you to iterate over every entity of a given kind, be it to extract their data, or to modify them and store the updated entities back to the datastore.

Run with it!

Now, start your appengine interactive console:

$python appengine_console.py <app_id_here>

That should start the interactive console. In it create a subclass of Model:

from utils import Mapper
# import your model class here 
class MyModelDeleter(Mapper):
    KIND = <model_name_here>

    def map(self, entity):
        return ([], [entity])

And, finally, run it (from you interactive console): mapper = MyModelDeleter() mapper.run()

That's it!

share|improve this answer

You can do it using the web interface. Login into your account, navigate with links on the left hand side. In Data Store management you have options to modify and delete data. Use respective options.

share|improve this answer

I've created an add-in panel that can be used with your deployed App Engine apps. It lists the kinds that are present in the datastore in a dropdown, and you can click a button to schedule "tasks" that delete all entities of a specific kind or simply everything. You can download it here:

share|improve this answer

For Python, 1.3.8 includes an experimental admin built-in for this. They say: "enable the following builtin in your app.yaml file:"

- datastore_admin: on

"Datastore delete is currently available only with the Python runtime. Java applications, however, can still take advantage of this feature by creating a non-default Python application version that enables Datastore Admin in the app.yaml. Native support for Java will be included in an upcoming release."

share|improve this answer
that's the currently easiest solution to bulk delete a specific entity –  systempuntoout Jan 18 '11 at 22:59
Adding the configuration in app.yaml threw an error. Instead we can enable it from the 'Applications Setting' Page in 'Administration' section. There's a button to enable it –  Sundeep Dec 29 '12 at 23:12

Open "Datastore Admin" for your application and enable Admin. Then all of your entities will be listed with check boxes. You can simply select the unwanted entites and delete them.

share|improve this answer

This is what you're looking for...


Running a keys-only query is much faster than a full fetch, and your quota will take a smaller hit because keys-only queries are considered small ops.

Here's a link to an answer from Nick Johnson describing it further.

Below is an end-to-end REST API solution to truncating a table...

I setup a REST API to handle database transactions where routes are directly mapped through to the proper model/action. This can be called by entering the right url (example.com/inventory/truncate) and logging in.

Here's the route:

Route('/inventory/truncate', DataHandler, defaults={'_model':'Inventory', '_action':'truncate'})

Here's the handler:

class DataHandler(webapp2.RequestHandler):
  def delete(self, **defaults):
    model = defaults.get('_model')
    action = defaults.get('_action')
    module = __import__('api.models', fromlist=[model])
    model_instance = getattr(module, model)()
    result = getattr(model_instance, action)()

It starts by loading the model dynamically (ie Inventory found under api.models), then calls the correct method (Inventory.truncate()) as specified in the action parameter.

The @basic_auth is a decorator/wrapper that provides authentication for sensitive operations (ie POST/DELETE). There's also an oAuth decorator available if you're concerned about security.

Finally, the action is called:

def truncate(self):

It looks like magic but it's actually very straightforward. The best part is, delete() can be re-used to handle deleting one-or-many results by adding another action to the model.

share|improve this answer

If you have a lot of data, using the web interface could be time consuming. The App Engine Launcher utility lets you delete everything in one go with the 'Clear datastore on launch' checkbox. This utility is now available for both Windows and Mac (Python framework).

share|improve this answer

For the development server, instead of running the server through the google app engine launcher, you can run it from the terminal like:

dev_appserver.py --port=[portnumber] --clear_datastore=yes [nameofapplication]

ex: my application "reader" runs on port 15080. After modify the code and restart the server, I just run "dev_appserver.py --port=15080 --clear_datastore=yes reader".

It's good for me.

share|improve this answer

Adding answer about recent developments.

Google recently added datastore admin feature. You can backup, delete or copy your entities to another app using this console.


share|improve this answer

PHP variation:

import com.google.appengine.api.datastore.Query;
import com.google.appengine.api.datastore.DatastoreServiceFactory;

define('DATASTORE_SERVICE', DatastoreServiceFactory::getDatastoreService());

function get_all($kind) {
    $query = new Query($kind);
    $prepared = DATASTORE_SERVICE->prepare($query);
    return $prepared->asIterable();

function delete_all($kind, $amount = 0) {
    if ($entities = get_all($kind)) {
        $r = $t = 0;
        $delete = array();
        foreach ($entities as $entity) {
            if ($r < 500) {
                $delete[] = $entity->getKey();
            } else {
                $delete = array();
                $r = -1;
            $r++; $t++;
            if ($amount && $amount < $t) break;
        if ($delete) {

Yes it will take time and 30 sec. is a limit. I'm thinking to put an ajax app sample to automate beyond 30 sec.

share|improve this answer
WTF? None of that is necessary. –  Evan Plaice Jun 1 '12 at 20:18

I often don't want to delete all the data store so I pull a clean copy of /war/WEB-INF/local_db.bin out source control. It may just be me but it seems even with the Dev Mode stopped I have to physically remove the file before pulling it. This is on Windows using the subversion plugin for Eclipse.

share|improve this answer

I was so frustrated about existing solutions for deleting all data in the live datastore that I created a small GAE app that can delete quite some amount of data within its 30 seconds.

How to install etc: http://code.google.com/p/xydra/wiki/GaeMyAdmin

share|improve this answer
for amodel in db.Model.__subclasses__():
                print amodel
                    m = amodel()
                    mq = m.all()
                    print mq.count()
                    for mw in mq:
            #~ print len(dela)

share|improve this answer

If you're using ndb, the method that worked for me for clearing the datastore:

share|improve this answer
I don't think this will work. Appengine complains about Sorry, unexpected error: The kind "__Stat_Kind__" is reserved. This seems like appengine has some internal statistics entity that can be exposed by this method (possible bug on their end?) –  disappearedng Jun 11 '14 at 7:55

For any datastore that's on app engine, rather than local, you can use the new Datastore API. Here's a primer for how to get started.

I wrote a script that deletes all non-built in entities. The API is changing pretty rapidly, so for reference, I cloned it at commit 990ab5c7f2063e8147bcc56ee222836fd3d6e15b

from gcloud import datastore
from gcloud.datastore import SCOPE
from gcloud.datastore.connection import Connection
from gcloud.datastore import query

from oauth2client import client

def get_connection():
  client_email = 'XXXXXXXX@developer.gserviceaccount.com'
  private_key_string = open('/path/to/yourfile.p12', 'rb').read()

  svc_account_credentials = client.SignedJwtAssertionCredentials(

  return Connection(credentials=svc_account_credentials)

def connect_to_dataset(dataset_id):
  connection = get_connection()

if __name__ == "__main__":
  gae_entity_query = query.Query()
  for entity in gae_entity_query.fetch():
    if entity.kind[0] != '_':
      print entity.kind
share|improve this answer

You can Delete All Datastore by deleting all Kinds One by One. with google appengine dash board. Please follow these Steps.

1- Login to https://appengine.google.com/

2- Click Data Store admin in data section.(Enable data store admin if not enabled.)

3- Select all Entities and press delete.(This Step run a map reduce job for deleting all selected Kinds.)

for more information see This image http://storage.googleapis.com/bnifsc/Screenshot%20from%202015-01-31%2023%3A58%3A41.png

share|improve this answer

There are several ways you can use to remove entries from App Engine's Datastore:

enter image description here

  1. First, think whether you really need to remove entries. This is expensive and it might be cheaper to not remove them.

  2. You can delete all entries by hand using the Datastore Admin.

  3. You can use the Remote API and remove entries interactively.

  4. You can remove the entries programmatically using a couple lines of code.

  5. You can remove them in bulk using Task Queues and Cursors.

  6. Or you can use Mapreduce to get something more robust and fancier.

Each one of these methods is explained in the following blog post: https://blog.svpino.com/2015/03/28/how-to-bulk-delete-entries-in-app-engine-datastore

Hope it helps!

share|improve this answer

Your Answer

