4

I am using Google AppEngine Endpoints to build a web API. I will consume it with a client written in Python. I know that scripts are provided to generate Android and iOS client API, but it doesn't seem that there is anything comparable for Python.

It does seem redundant to code everything again. For instance, the messages definition which are basically the same.

It there anyway of getting this done more easily?

Thanks

seven-down
  • 126
  • 10

2 Answers2

12

You can use the Google APIs Client Library for Python which is compatible with endpoints.

Normally you would build a client using service = build(api, version, http=http) for example service = build("plus", "v1", http=http) to build a client to access to Google+ API.

For using the library for your endpoint you would use:

service = build("your_api", "your_api_version", http=http, 
  discoveryServiceUrl=("https://yourapp.appspot.com/_ah/api/discovery/v1/"
                       "apis/{api}/{apiVersion}/rest"))

You can then access your API with

result = service.resource().method([parameters]).execute()
Scarygami
  • 15,009
  • 2
  • 35
  • 24
  • Wow thanks a lot. I will test this tomorrow and come back to give your my results :) – seven-down May 01 '13 at 14:11
  • Make sure to check the documentation of the Client library: https://developers.google.com/api-client-library/python/start/get_started Basically everything they describe for Google APIs is valid for your endpoints as well (including authentication if you need it) – Scarygami May 01 '13 at 14:13
  • 2
    I finally had some time to try it. I removed the `http=http` from the build. I wanted to try it locally, but it's not possible to enable https on the GAE dev server and even if I put the discovery url to be http, it then switch to https to make any request which doesn't work. I can deploy it to the GAE but then it is less practical since I cannot directly edit my datastore. So it does work, but it is not really practical for development environment I guess. Thanks again. – seven-down May 07 '13 at 10:11
3

Here's what happens with the endpoints helloworld greetings example:

__author__ = 'robertking'

import httplib2
from apiclient.discovery import build

http = httplib2.Http()

service = build("helloworld", "v1", http=http,
  discoveryServiceUrl=("http://localhost:8080/_ah/api/discovery/v1/apis/helloworld/v1/rest"))

print service.greetings().listGreeting().execute()['items']

"""
prints
[{u'message': u'hello world!'}, {u'message': u'goodbye world!'}]
"""

Right now I'm using http.

Rusty Rob
  • 16,489
  • 8
  • 100
  • 116