Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



Remote API for Python

The Python SDK includes a library called Remote API that lets you transparently access App Engine services from any Python application. For example, you can use Remote API to access a production datastore from an app running on your local machine.

Enabling Remote API

You can enable the Remote API using either the builtins directive, which will make the Remote API available on the default path, or the url directive. Note that if the URL is changed, all applications that connect to the App Engine application will need to change the URL as well. Both methods are detailed below.

Default URL

To map the Remote API to the default path ( /_ah/remote_api ), add the remote_api builtin to your app.yaml file:

builtins:
- remote_api: on

Custom URL

If you need to map the Remote API to a path other than the default, you can use the url directive in app.yaml :

For Python 2.7:

- url: /remoteapi.*
  script: google.appengine.ext.remote_api.handler.application
  login: admin

For Python 2.5:

- url: /remoteapi.*
  script: $PYTHON_LIB/google/appengine/ext/remote_api/handler.py
  login: admin

Using the Remote API Shell

The Python SDK includes a Remote API shell which allows you to run a shell that has access to App Engine services and your applications datastore.

To use modules defined by your application you will need to run the Remote API shell from your application's directory. From the application directory, execute the command:

$GAE_SDK_ROOT/remote_api_shell.py -s <your_app_id>.appspot.com

From the Remote API shell you can simply import application modules just as you would in a normal App Engine application. An example of accessing the Guestbook applications datastore is below:

>>>> import helloworld
>>> # Fetch the most recent 10 guestbook entries
>>> entries = helloworld.Greeting.all().order("-date").fetch(10)
>>>
>>> # Create our own guestbook entry
>>> helloworld.Greeting(content="A greeting").put()

In general, the Remote API shell behaves exactly as if you were accessing the datastore directly. However because the script is running on your local machine, you can access files and resources on your local machine. There are however limitations to the Remote API which are discussed along with best practises in the Remote API article .

Using the Remote API in a Local Client

The Remote API can also be used within local applications. This will allow you to write local applications that use App Engine services and access datastore. It is important to note that using the Remote API will incur quota usage on the application you are accessing. Other limitations of the Remote API are discussed in the Remote API article.

Before beginning, make sure the App Engine SDK is added to your Python path and Remote API is enabled in your App Engine application. An example local application that uses Remote API and the Guestbook application is shown below:

from google.appengine.ext.remote_api import remote_api_stub
from helloworld import helloworld
import getpass

def auth_func():
  return (raw_input('Username:'), getpass.getpass('Password:'))

remote_api_stub.ConfigureRemoteApi(None, '/_ah/remote_api', auth_func,
                               '<i>your_app_id</i>.appspot.com')

# Fetch the most recent 10 guestbook entries
entries = helloworld.Greeting.all().order("-date").fetch(10)
# Create our own guestbook entry
helloworld.Greeting(content="A greeting").put()

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.