Company Blog

SCIENCE - TECHNOLOGY - SOLUTIONS

Google Maps Engine: Python Basics - Part 2

A few weeks ago I posted regarding the basics of terminology and authentication for Google Maps Engine (GME) via the Python API.  In this post we will cover the installation of the API, including verification of dependencies.  This is one lesson that I learned the hard way, so hopefully I can make it a little easier on you.

To begin let's look at the API architecture and try to understand the core dependencies.  This will help us out in debugging our installation and use.  The PyDoc documentation of the API is a good place to start (http://google-api-python-client.googlecode.com/hg/docs/epy/frames.html).  As documented in the previous link, here are some of the dependencies to be aware of.

  1. Python 2.7 or higher is suggested
  2. pyOpenSSL is required
    1. Subdependencies include libcffi in order to be able to install Cryptography
  3. pyCrypto is required

Depending on your operating system there are different ways to install the API.  For Linux and Mac, make sure you have a current installation of Setuptools or pip.  Then execute the following;

easy_install --upgrade google-api-python-client

OR

pip install --upgrade google-api-python-client

For Microsoft Windows;
  1. Download the API from here.
  2. Unzip the package to a location where you have rights
  3. Open a command prompt and navigate to the new directory
  4. Execute python setup.py install
To test your installation, open a Python prompt and execute the following;
from oauth2client.client import SignedJwtAssertionCredentials

If this returns an error, you most likely have a problem with your pyOpenSSL configuration.  Go here to start to debug problems with the pyOpenSSL installation.

Otherwise you have successfully installed the API and are now ready to proceed with setup your code.

In part 3, we will cover the actual code and the required elements to interface with GME.

Google Maps Engine: Python Basics - Part 1

In case you haven't heard of it, Google has been working on a project for a little over a year or so call Google Maps Engine (GME).  GME is a really powerful cloud-based mapping system that is maturing at a really nice pace.  One of the nice features about it is its accessibility via multiple API's.  One of those API's is Python.  There are some pretty good tutorials (https://developers.google.com/maps-engine/documentation/tutorial) and documentation including an API reference with some examples (https://developers.google.com/maps-engine/documentation/reference/v1/).

However, one thing that is a little lacking is documentation on how the OAuth2 authentication protocol is leveraged in Python.  I have to admit that I struggled some here until I was aided by my friend at Google, Sean Wohltman.  So Sean, much thanks for all your help and guidance.

Before we begin, there is one thing that you must understand to make sure we are consistent in our references, that is the terminology (https://developers.google.com/maps-engine/documentation/definitions).



So with this as the foundation of the discussion, we can loosely refer to these as the accessible objects through the API.

The approach to for the purposes of this article are relatively simple.  We will authenticate and then we will retrieve a collection of each of the objects.  This will demonstrate the core functionality that we have through the Python API.

To start the process of authentication, let's first refer to some of the basics in documentation.



Now that we have a basic understanding of the OAuth2 protocol, you can get the API downloaded and installed.  The Google APIs Client Library for Python is located at (https://code.google.com/p/google-api-python-client/downloads/list).

In Part 2 of this series we will cover the set up and use of the API in Python.