Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine Local (Development) IPython Shell

In my local Google app engine development environment, I would like to use an ipython shell, especially to be able to check out models with data that was created via dev_server.py, very much like how django's manage.py shell command works.

(This means that the ipython shell should be started after sys.path was fixed and app.yaml was read and analyzed, and the local datastore is ready)

Any simple solution for this?

like image 231
Udi Avatar asked Jan 22 '13 23:01

Udi


2 Answers

For starters, you can put your application root directory and the SDK root directory (google_appengine) in your Python path. You'll also need a few libraries like yaml, either installed or added to the library path from the SDK's lib directory. Then you can import modules and call some features.

>>> import sys
>>> sys.path.append('/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine')

Of course, as soon as a code path tries to make a service call, the library will raise an exception, saying it isn't bound to anything. To bind the service libraries to test stubs, use the testbed library:

>>> from google.appengine.ext import testbed
>>> tb = testbed.Testbed()
>>> tb.activate()
>>> tb.init_datastore_v3_stub()
>>> from google.appengine.ext import db
>>> import models
>>> m = models.Entry()
>>> m.title = ‘Test’
>>> m.put()

To tell the datastore test stub to use your development server's datastore file, pass the path to the file to init_datastore_v3_stub() as the datastore_file argument. See the doc comment for the method in google.appengine.ext.testbed for more information.

For more information on testbed: https://developers.google.com/appengine/docs/python/tools/localunittesting

like image 54
Dan Sanderson Avatar answered Oct 27 '22 20:10

Dan Sanderson


Basically you'll need to use this: https://developers.google.com/appengine/articles/remote_api

For IPython support you have two options:

(1) If you're working with Python 2.7 (and IPython 0.13) you will need to use this to embed an IPython shell:

from IPython.frontend.terminal.interactiveshell import TerminalInteractiveShell
shell = TerminalInteractiveShell(user_ns=namespace)
shell.mainloop()

(2) If you're working with Python 2.5 (and IPython 0.10.2) you will need to use this line to embed an IPython shell:

from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(user_ns=namespace, banner=banner)
ipshell()

This is the one that I use: https://gist.github.com/4624108 so you just type..

>> python console.py your-app-id
like image 37
Jairo Vasquez Avatar answered Oct 27 '22 21:10

Jairo Vasquez