How do you set up a shell to run NDB. Everything imports OK, but when
I run for instance a get from a key I get:
AssertionError: No api proxy found for service "memcache"
I have my dev appserver running, I am guessing, there is some setup
piece I need to do. Probably something similar to the work done at the
top of the unit test harness.
--
Michael Robellard
(216)288-2745
Play Railroad Empire: http://www.therailroadempire.com
import os
from google.appengine.api import apiproxy_stub_map
from google.appengine.api import datastore_file_stub
from google.appengine.api import memcache
from google.appengine.api.memcache import memcache_stub
from google.appengine.api import taskqueue
from google.appengine.api.taskqueue import taskqueue_stub
from google.appengine.api import urlfetch_stub
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
ds_stub = datastore_file_stub.DatastoreFileStub('_', None)
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub)
mc_stub = memcache_stub.MemcacheServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('memcache', mc_stub)
tq_stub = taskqueue_stub.TaskQueueServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('taskqueue', tq_stub)
uf_stub = urlfetch_stub.URLFetchServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', uf_stub)
os.environ['APPLICATION_ID'] = '_'
If you want the datastore contents to persist, you'll have to pass a
file to the DatastoreFileStub constructor. If you want to read/write
the data written by your app (running in dev_appserver) you have to
make sure the filename matches the --datastore_path argument to
dev_appserver.py, and you have to make the appid match app.yaml (the
above code uses '_' in a few places).
Finally, you can also do it with remote_api, but that's a different
setup -- you probably have to read the docs for remote_api. That way
it would access the real datastore associated with your app. (But
beware that the assumptions NDB makes about Context lifetime might be
incorrect in that case.)
--Guido
--
--Guido van Rossum (python.org/~guido)
This is exactly what I need.