Skip to content

Instantly share code, notes, and snippets.

@sahid
Created December 20, 2010 17:39
Show Gist options
  • Save sahid/748691 to your computer and use it in GitHub Desktop.
Save sahid/748691 to your computer and use it in GitHub Desktop.
Async insert on Google App Engine
import os
import logging
from google.appengine.ext import db
from google.appengine.api import datastore
from google.appengine.datastore import datastore_rpc
def async_put(entities, **kwargs):
config = datastore.CreateConfig(**kwargs)
entities, _ = datastore.NormalizeAndTypeCheck(entities, db.Model)
entities = [model._populate_internal_entity() for model in entities]
conn = datastore_rpc.Connection(adapter=datastore.DatastoreAdapter())
rpcs = conn.async_put(config, entities)
if os.environ['SERVER_SOFTWARE'].startswith('Dev'):
rpcs.wait() # To execute the request in dev.
return rpcs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment