Client for discovery based APIs.
A client library for Google's discovery based APIs.
| Class | |
A class for interacting with a resource. |
| Class | |
Represents the parameters associated with a method. |
| Exception | |
Undocumented |
| Function | build |
Construct a Resource for interacting with an API. |
| Function | build |
Create a Resource for interacting with an API. |
| Function | create |
Creates a method for attaching to a Resource. |
| Function | create |
Creates any _next methods for attaching to a Resource. |
| Function | fix |
Fix method names to avoid '$' characters and reserved word conflicts. |
| Function | key2param |
Converts key names into parameter names. |
| Constant | BODY |
Undocumented |
| Constant | DEFAULT |
Undocumented |
| Constant | DEFAULT |
Undocumented |
| Constant | DISCOVERY |
Undocumented |
| Constant | GOOGLE |
Undocumented |
| Constant | GOOGLE |
Undocumented |
| Constant | GOOGLE |
Undocumented |
| Constant | HTTP |
Undocumented |
| Constant | MEDIA |
Undocumented |
| Constant | MEDIA |
Undocumented |
| Constant | RESERVED |
Undocumented |
| Constant | STACK |
Undocumented |
| Constant | STACK |
Undocumented |
| Constant | URITEMPLATE |
Undocumented |
| Constant | V2 |
Undocumented |
| Constant | VARNAME |
Undocumented |
| Variable | __author__ |
Undocumented |
| Variable | HAS |
Undocumented |
| Variable | logger |
Undocumented |
| Class | _ |
Undocumented |
| Function | _cast |
Convert value to a string based on JSON Schema type. |
| Function | _check |
Undocumented |
| Function | _discovery |
Returns Discovery URIs to be used for attempting to build the API Resource. |
| Function | _find |
Search field names for one like a page token. |
| Function | _fix |
Update the media upload base url if its netloc doesn't match base url netloc. |
| Function | _fix |
Adds 'media_body' and 'media_mime_type' parameters if supported by method. |
| Function | _fix |
Updates a method description in a discovery document. |
| Function | _fix |
Updates parameters of an API method with values specific to this library. |
| Function | _media |
Creates an absolute media path URL. |
| Function | _media |
Convert a string media size, such as 10GB or 3TB into an integer. |
| Function | _method |
Get properties of a field in a method description. |
| Function | _retrieve |
Retrieves the discovery_doc from cache or the internet. |
| Function | _urljoin |
Custom urljoin replacement supporting : before / in url. |
| Constant | _MEDIA |
Undocumented |
| Constant | _PAGE |
Undocumented |
def build(serviceName, version, http=None, discoveryServiceUrl=None, developerKey=None, model=None, requestBuilder=HttpRequest, credentials=None, cache_discovery=True, cache=None, client_options=None, adc_cert_path=None, adc_key_path=None, num_retries=1, static_discovery=None, always_use_jwt_access=False): ¶
Construct a Resource for interacting with an API.
Construct a Resource object for interacting with an API. The serviceName and version are the names from the Discovery service.
| Parameters | |
| service | string, name of the service. |
| version | string, the version of the service. |
| http | httplib2.Http, An instance of httplib2.Http or something that acts like it that HTTP requests will be made through. |
| discovery | string, a URI Template that points to the location of the discovery service. It should have two parameters {api} and {apiVersion} that when filled in produce an absolute URI to the discovery document for that service. |
| developer | string, key obtained from https://code.google.com/apis/console. |
| model | googleapiclient.Model, converts to and from the wire format. |
| request | googleapiclient.http.HttpRequest, encapsulator for an HTTP request. |
| credentials | oauth2client.Credentials or google.auth.credentials.Credentials, credentials to be used for authentication. |
| cache | Boolean, whether or not to cache the discovery doc. |
| cache | googleapiclient.discovery_cache.base.CacheBase, an optional cache object for the discovery documents. |
| client | Mapping object or google.api_core.client_options, client
options to set user options on the client.
(1) The API endpoint should be set through client_options. If API endpoint
is not set, GOOGLE_API_USE_MTLS_ENDPOINT environment variable can be used
to control which endpoint to use.
(2) client_cert_source is not supported, client cert should be provided using
client_encrypted_cert_source instead. In order to use the provided client
cert, GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable must be
set to true.
More details on the environment variables are here:
https://google.aip.dev/auth/4114 |
| adc | str, client certificate file path to save the application
default client certificate for mTLS. This field is required if you want to
use the default client certificate. GOOGLE_API_USE_CLIENT_CERTIFICATE
environment variable must be set to true in order to use this field,
otherwise this field doesn't nothing.
More details on the environment variables are here:
https://google.aip.dev/auth/4114 |
| adc | str, client encrypted private key file path to save the
application default client encrypted private key for mTLS. This field is
required if you want to use the default client certificate.
GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable must be set to
true in order to use this field, otherwise this field doesn't nothing.
More details on the environment variables are here:
https://google.aip.dev/auth/4114 |
| num | Integer, number of times to retry discovery with randomized exponential backoff in case of intermittent/connection issues. |
| static | Boolean, whether or not to use the static discovery docs
included in the library. The default value for static_discovery depends
on the value of discoveryServiceUrl. static_discovery will default to
True when discoveryServiceUrl is also not provided, otherwise it will
default to False. |
| always | Boolean, whether always use self signed JWT for service account credentials. This only applies to google.oauth2.service_account.Credentials. |
| Returns | |
| A Resource object with methods for interacting with the service. | |
| Raises | |
google.auth.exceptions.MutualTLSChannelError | if there are any problems setting up mutual TLS channel. |
def build_from_document(service, base=None, future=None, http=None, developerKey=None, model=None, requestBuilder=HttpRequest, credentials=None, client_options=None, adc_cert_path=None, adc_key_path=None, always_use_jwt_access=False): ¶
Create a Resource for interacting with an API.
Same as build(), but constructs the Resource object from a discovery
document that is it given, as opposed to retrieving one over HTTP.
| Parameters | |
| service | string or object, the JSON discovery document describing the API. The value passed in may either be the JSON string or the deserialized JSON. |
| base | string, base URI for all HTTP requests, usually the discovery URI. This parameter is no longer used as rootUrl and servicePath are included within the discovery document. (deprecated) |
| future | string, discovery document with future capabilities (deprecated). |
| http | httplib2.Http, An instance of httplib2.Http or something that acts like it that HTTP requests will be made through. |
| developer | string, Key for controlling API usage, generated from the API Console. |
| model | Model class instance that serializes and de-serializes requests and responses. |
| request | Takes an http request and packages it up to be executed. |
| credentials | oauth2client.Credentials or google.auth.credentials.Credentials, credentials to be used for authentication. |
| client | Mapping object or google.api_core.client_options, client
options to set user options on the client.
(1) The API endpoint should be set through client_options. If API endpoint
is not set, GOOGLE_API_USE_MTLS_ENDPOINT environment variable can be used
to control which endpoint to use.
(2) client_cert_source is not supported, client cert should be provided using
client_encrypted_cert_source instead. In order to use the provided client
cert, GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable must be
set to true.
More details on the environment variables are here:
https://google.aip.dev/auth/4114 |
| adc | str, client certificate file path to save the application
default client certificate for mTLS. This field is required if you want to
use the default client certificate. GOOGLE_API_USE_CLIENT_CERTIFICATE
environment variable must be set to true in order to use this field,
otherwise this field doesn't nothing.
More details on the environment variables are here:
https://google.aip.dev/auth/4114 |
| adc | str, client encrypted private key file path to save the
application default client encrypted private key for mTLS. This field is
required if you want to use the default client certificate.
GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable must be set to
true in order to use this field, otherwise this field doesn't nothing.
More details on the environment variables are here:
https://google.aip.dev/auth/4114 |
| always | Boolean, whether always use self signed JWT for service account credentials. This only applies to google.oauth2.service_account.Credentials. |
| Returns | |
| A Resource object with methods for interacting with the service. | |
| Raises | |
google.auth.exceptions.MutualTLSChannelError | if there are any problems setting up mutual TLS channel. |
Creates a method for attaching to a Resource.
| Parameters | |
| method | string, name of the method to use. |
| method | object, fragment of deserialized discovery document that describes the method. |
| root | object, the entire deserialized discovery document. |
| schema | object, mapping of schema names to schema descriptions. |
Creates any _next methods for attaching to a Resource.
The _next methods allow for easy iteration through list() responses.
| Parameters | |
| method | string, name of the method to use. |
| page | string, name of request page token field. |
| next | string, name of response page token field. |
| is | Boolean, True if request page token is a query parameter, False if request page token is a field of the request body. |
Fix method names to avoid '$' characters and reserved word conflicts.
| Parameters | |
| name | string, method name. |
| Returns | |
| The name with '_' appended if the name is a reserved word and '$' and '-' replaced with '_'. | |
Converts key names into parameter names.
For example, converting "max-results" -> "max_results"
| Parameters | |
| key | string, the method key name. |
| Returns | |
| A safe method name based on the key name. | |
Undocumented
| Value |
|
Undocumented
| Value |
|
Convert value to a string based on JSON Schema type.
See http://tools.ietf.org/html/draft-zyp-json-schema-03 for more details on JSON Schema.
| Parameters | |
| value | any, the value to convert |
| schema | string, the type that value should be interpreted as |
| Returns | |
| A string representation of 'value' based on the schema_type. | |
Returns Discovery URIs to be used for attempting to build the API Resource.
| Parameters | |
| discovery | string, the Original Discovery Service URL preferred by the customer. |
| version | string, API Version requested |
| Returns | |
| A list of URIs to be tried for the Service Discovery, in order. | |
Search field names for one like a page token.
| Parameters | |
| fields | container of string, names of fields. |
| Returns | |
| First name that is either 'pageToken' or 'nextPageToken' if one exists, otherwise None. | |
Update the media upload base url if its netloc doesn't match base url netloc.
This can happen in case the base url was overridden by client_options.api_endpoint.
| Parameters | |
| media | String; the absolute URI for media upload. |
| base | string, base URL for the API. All requests are relative to this URI. |
| Returns | |
| String; the absolute URI for media upload. | |
Adds 'media_body' and 'media_mime_type' parameters if supported by method.
SIDE EFFECTS: If there is a 'mediaUpload' in the method description, adds 'media_upload' key to parameters.
| Parameters | |
| method | Dictionary with metadata describing an API method. Value comes from the dictionary of methods stored in the 'methods' key in the deserialized discovery document. |
| root | Dictionary; the entire original deserialized discovery document. |
| path | String; the relative URL for the API method. Relative to the API root, which is specified in the discovery document. |
| parameters | A dictionary describing method parameters for method described in method_desc. |
| Returns | |
Triple(accept, max_size, media_path_url)where |
|
Updates a method description in a discovery document.
SIDE EFFECTS: Changes the parameters dictionary in the method description with extra parameters which are used locally.
| Parameters | |
| method | Dictionary with metadata describing an API method. Value comes from the dictionary of methods stored in the 'methods' key in the deserialized discovery document. |
| root | Dictionary; the entire original deserialized discovery document. |
| schema | Object, mapping of schema names to schema descriptions. |
| Returns | |
Tuple(path_url, http_method, method_id, accept, max_size, media_path_url) |
|
Updates parameters of an API method with values specific to this library.
Specifically, adds whatever global parameters are specified by the API to the parameters for the individual method. Also adds parameters which don't appear in the discovery document, but are available to all discovery based APIs (these are listed in STACK_QUERY_PARAMETERS).
SIDE EFFECTS: This updates the parameters dictionary object in the method description.
| Parameters | |
| method | Dictionary with metadata describing an API method. Value comes from the dictionary of methods stored in the 'methods' key in the deserialized discovery document. |
| root | Dictionary; the entire original deserialized discovery document. |
| http | String; the HTTP method used to call the API method described in method_desc. |
| schema | Object, mapping of schema names to schema descriptions. |
| Returns | |
| |
Creates an absolute media path URL.
Constructed using the API root URI and service path from the discovery document and the relative path for the API method.
| Parameters | |
| root | Dictionary; the entire original deserialized discovery document. |
| path | String; the relative URL for the API method. Relative to the API root, which is specified in the discovery document. |
| Returns | |
| String; the absolute URI for media upload for the API method. | |
Convert a string media size, such as 10GB or 3TB into an integer.
| Parameters | |
| max | string, size as a string, such as 2MB or 7GB. |
| Returns | |
| The size as an integer value. | |
Get properties of a field in a method description.
| Parameters | |
| method | object, fragment of deserialized discovery document that describes the method. |
| schema | object, mapping of schema names to schema descriptions. |
| name | string, name of top-level field in method description. |
| Returns | |
| Object representing fragment of deserialized discovery document corresponding to 'properties' field of object corresponding to named field in method description, if it exists, otherwise empty dict. | |
Retrieves the discovery_doc from cache or the internet.
| Parameters | |
| url | string, the URL of the discovery document. |
| http | httplib2.Http, An instance of httplib2.Http or something that acts like it through which HTTP requests will be made. |
| cache | Boolean, whether or not to cache the discovery doc. |
| service | string, name of the service. |
| version | string, the version of the service. |
| cache | googleapiclient.discovery_cache.base.Cache, an optional cache object for the discovery documents. |
| developer | string, Key for controlling API usage, generated from the API Console. |
| num | Integer, number of times to retry discovery with randomized exponential backoff in case of intermittent/connection issues. |
| static | Boolean, whether or not to use the static discovery docs included in the library. |
| Returns | |
| A unicode string representation of the discovery document. | |