Click here to see your recently viewed pages and most viewed pages.
Hide

Interactive Help

You can use Python's help() function in an interactive Python shell to view PyDoc generated documentation at the command-line. This is particularly useful to explore API methods. To do this, construct a service object for the API you are interested in and call help on the objects you construct.

From the command-line, start Python, build a service object, and get help on the service:

$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from apiclient.discovery import build
>>> service = build("latitude", "v1")
>>> help(service)

Help on Resource in module apiclient.discovery object:

class Resource(__builtin__.object)
 |  A class for interacting with a resource.
 |
 |  Methods defined here:
 |
 |  __init__(self)
 |
 |  currentLocation = methodResource(self)
 |      A collection resource.
 |
 |  location = methodResource(self)
 |      A collection resource.
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)

Note: The build() function generates a service object at run time, so the initial help information describing an object is too generic to be useful. You can ignore the help header when looking for API-specific details.

The help command above output lists currentLocation and location as collection resources. Get help on the location collection:

>>> help(service.location())

Help on Resource in module apiclient.discovery object:

class Resource(__builtin__.object)
 |  A class for interacting with a resource.
 |
 |  Methods defined here:
 |
 |  __init__(self)
 |
 |  delete = method(self, **kwargs)
 |      Deletes a location from the user's location history.
 |
 |      Args:
 |        locationId: string, Timestamp of the location to delete (ms since epoch). (required)
 |
 |  get = method(self, **kwargs)
 |      Reads a location from the user's location history.
 |
 |      Args:
 |        locationId: string, Timestamp of the location to read (ms since epoch). (required)
 |        granularity: string, Granularity of the location to return.
 |
 |      Returns:
 |        An object of the form
 |
 |          { # A Location resource identifies a user's position at a particular time. It may include metadata about the user's position, such as a venue if the location was recorded at the time of a check-in.
 |            "kind": "latitude#location", # Kind of this item.
 |            "altitude": "", # Altitude of the location, in meters. Optional.
 |            "longitude": "", # Longitude of the location, in decimal degrees.
 |            "activityId": "", # Unique ID of the Buzz message that corresponds to the check-in associated with this location. Available only for check-in locations. Optional.
 |            "latitude": "", # Latitude of the location, in decimal degrees.
 |            "altitudeAccuracy": "", # Accuracy of the altitude value, in meters. Optional.
 |            "timestampMs": "", # Timestamp of the Location Resource, in milliseconds since the epoch (UTC). This is also the Location Resource's unique id.
 |            "speed": "", # Ground speed of the user at the time this location was recorded, in meters per second. Non-negative. Optional.
 |            "heading": "", # Direction of travel of the user when this location was recorded. In degrees, clockwise relative to true north. Optional.
 |            "accuracy": "", # Accuracy of the latitude and longitude coordinates, in non-negative meters. Optional.
 |          }
 |
...
 |
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |
 |  __dict__
 |      dictionary for instance variables (if defined)
 |
 |  __weakref__
 |      list of weak references to the object (if defined)

The help output lists delete as a method. Get help on the delete method:

>>> help(service.location().delete)

Help on method method in module apiclient.discovery:

method(self, **kwargs) method of apiclient.discovery.Resource instance
    Deletes a location from the user's location history.

    Args:
      locationId: string, Timestamp of the location to delete (ms since epoch). (required)

For each method, the arguments are listed along with their types and descriptions. For example, the list method has min_time, max_results, max_time, and granularity arguments.

The (required) flag indicates that the argument must be supplied when calling the method; otherwise the argument is optional.

Method arguments may also be flagged as (repeated) which indicates that you may pass in a Python list of values for that argument.