Skip to content

Instantly share code, notes, and snippets.

@djm
Created September 28, 2014 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save djm/016a6cdbc6be02a08c3b to your computer and use it in GitHub Desktop.
Save djm/016a6cdbc6be02a08c3b to your computer and use it in GitHub Desktop.
Google App Engine Development Shell
#!/usr/bin/env python -i
"""
A local interactive IPython shell for Google App Engine on Mac OSX.
Usage:
cd /to/project/folder/with/app.yaml
python gae_shell.py
Notes:
This script assumes numerous things:
* The path to your GAE SDK install.
* That you run the dev server with the specified datastore path:
e.g dev_appserver.py src --datastore_path=src/tmp/datastore
"""
import os
import sys
app_root = os.path.dirname(os.path.abspath(__file__))
location = lambda x: os.path.join(app_root, x)
sys.path.insert(0, app_root)
sys.path.insert(1, '/usr/local/google_appengine')
from google.appengine.api import apiproxy_stub_map
from google.appengine.datastore.datastore_sqlite_stub import (
DatastoreSqliteStub
)
from google.appengine.api.memcache.memcache_stub import MemcacheServiceStub
from google.appengine.api.taskqueue.taskqueue_stub import TaskQueueServiceStub
from google.appengine.api.urlfetch_stub import URLFetchServiceStub
from google.appengine.api import appinfo
ds_path = location("tmp/datastore")
# Load the app.yaml config.
app_ext_info = appinfo.LoadSingleAppInfo(file(location('app.yaml'), 'r'))
app_id = 'dev~%s' % app_ext_info.application
# Set the application ID to make stubs happy.
os.environ['APPLICATION_ID'] = app_id
# Init the proxy map and stubs.
apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap()
# SQLite Datastore setup.
ds_opts = {
'require_indexes': True,
'verbose': True
}
ds_stub = DatastoreSqliteStub(app_id, ds_path, **ds_opts)
apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', ds_stub)
# Memcache setup.
mc_stub = MemcacheServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('memcache', mc_stub)
# Task queues setup.
tq_stub = TaskQueueServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('taskqueue', tq_stub)
# URLfetch service setup.
uf_stub = URLFetchServiceStub()
apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', uf_stub)
# Pretty printing
import pprint
pp = pprint.PrettyPrinter(indent=4).pprint
# Perhaps load the models from your project
# so that they are already in the namespace.
# from project.models import *
from IPython import embed
embed()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment