oauth2client.clientsecrets module

Utilities for reading OAuth 2.0 client secret files.

A client_secrets.json file contains all the information needed to interact with an OAuth 2.0 protected service.

exception oauth2client.clientsecrets.Error[source]

Bases: exceptions.Exception

Base error for this module.

exception oauth2client.clientsecrets.InvalidClientSecretsError[source]

Bases: oauth2client.clientsecrets.Error

Format of ClientSecrets file is invalid.

oauth2client.clientsecrets.loadfile(filename, cache=None)[source]

Loading of client_secrets JSON file, optionally backed by a cache.

Typical cache storage would be App Engine memcache service, but you can pass in any other cache client that implements these methods:

  • get(key, namespace=ns)
  • set(key, value, namespace=ns)


# without caching
client_type, client_info = loadfile('secrets.json')
# using App Engine memcache service
from google.appengine.api import memcache
client_type, client_info = loadfile('secrets.json', cache=memcache)
  • filename – string, Path to a client_secrets.json file on a filesystem.
  • cache – An optional cache service client that implements get() and set()
  • If not specified, the file is always being loaded from (methods.) – a filesystem.

InvalidClientSecretsError – In case of a validation error or some I/O failure. Can happen only on cache miss.


(client_type, client_info) tuple, as _loadfile() normally would. JSON contents is validated only during first load. Cache hits are not validated.