Wednesday, March 4, 2009

Appengine remote_api example on OS X

The appengine team recently published an article on using remote_api, a new feature for accessing your appengine data store from a remote process. In the example they start off with a script that will allow you to get a console into your data store. The code on the site doesn't work as in for Mac OS X.

Below you'll find an updated example that does work for Mac. Basically you have to add the yaml lib directory to the sys.path.

#!/usr/bin/python
import code
import getpass
import os
import sys

DIR_PATH = "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine"

EXTRA_PATHS = [
  DIR_PATH,
  os.path.join(DIR_PATH, 'lib', 'yaml', 'lib'),
]

sys.path = EXTRA_PATHS + sys.path

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]
else:
  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())

That's all it takes. Hope you find it helpful. I'll also drop a line to the appengine team to let them know about these changes.

6 comments:

TCG2EyAll4n.cXcaosz6PAWPrwu0jweC said...

that was just what I needed. Thanks!

Steph Thirion said...

That did the trick! Thanks !!

Chris said...

For me it didn't work on Windows either until I did this. Thanks!

David Tussey said...

Very helpful BTW...on Windows it's

sys.path.append("C:\Program Files\Google\google_appengine\lib\yaml\lib")

Weird that Google "forgot" to mention that you had to add that path in to use the remote_api. Thanks for the article. Great catch.

Anonymous said...

I solved the problem installing the yaml module bundled in the google appengine

> cd [google-appengine-dir]
> cd lib/yaml
> sudo python setup.py install

No google code modifications needed in my Ubuntu

cabhishek said...

on my vista 64-bit i did
sys.path.append("C:\Program Files (x86)\Google\google_appengine\lib\yaml\lib")

but i am still getting the same error ?? can any one help me out.. its annoying