本文整理汇总了Python中googleapiclient.discovery.build方法的典型用法代码示例。如果您正苦于以下问题:Python discovery.build方法的具体用法?Python discovery.build怎么用?Python discovery.build使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类googleapiclient.discovery
的用法示例。
在下文中一共展示了discovery.build方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_cloud_mlengine_request_fn
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def make_cloud_mlengine_request_fn(credentials, model_name, version):
"""Wraps function to make CloudML Engine requests with runtime args."""
def _make_cloud_mlengine_request(examples):
"""Builds and sends requests to Cloud ML Engine."""
api = discovery.build("ml", "v1", credentials=credentials)
parent = "projects/%s/models/%s/versions/%s" % (cloud.default_project(),
model_name, version)
input_data = {
"instances": [{
"input": {
"b64": base64.b64encode(ex.SerializeToString())
}
} for ex in examples]
}
prediction = api.projects().predict(body=input_data, name=parent).execute()
return prediction["predictions"]
return _make_cloud_mlengine_request
示例2: get_api_client
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def get_api_client(self, service, version, scopes):
"""Gets an authenticated api connection to the provided service and version.
Args:
service: str, the name of the service to connect to.
version: str, the version of the service to connect to.
scopes: List[str], a list of the required scopes for this api call.
Returns:
An authenticated api client connection.
"""
if not self._credentials.has_scopes(scopes):
scopes.extend(self._credentials.scopes)
self._credentials = self.get_credentials(scopes)
return build(
serviceName=service, version=version,
http=google_auth_httplib2.AuthorizedHttp(credentials=self._credentials))
示例3: __init__
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def __init__(self, api, option="pandas"):
self.YOUTUBE_READ_WRITE_SSL_SCOPE = "https://www.googleapis.com/auth/youtube.force-ssl"
self.YOUTUBE_API_SERVICE_NAME = 'youtube'
self.YOUTUBE_API_VERSION = 'v3'
self.DEVELOPER_KEY = api["api_key"]
# This variable defines a message to display if the CLIENT_SECRETS_FILE is
# missing.
self.MISSING_CLIENT_SECRET_MESSAGE = """
WARNING: Please configure OAuth 2.0
To run you will need to populate the client_secrets.json file
with information from the APIs Console
https://console.developers.google.com"""
self.option = option
self.youtube = build(self.YOUTUBE_API_SERVICE_NAME, self.YOUTUBE_API_VERSION,
developerKey=self.DEVELOPER_KEY)
示例4: list_tpus
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def list_tpus(project, location):
"""List existing TPU nodes in the project/location.
Args:
project: (str) GCP project id.
location: (str) GCP compute location, such as "us-central1-b".
Returns
A Python dictionary with keys 'nodes' and 'nextPageToken'.
"""
service = discovery.build('tpu', 'v1', credentials=credentials)
parent = 'projects/{}/locations/{}'.format(project, location)
request = service.projects().locations().nodes().list(parent=parent)
return request.execute()
示例5: get_tpu
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def get_tpu(project, location, tpu_name):
"""List existing TPU nodes in the project/location.
Args:
project: (str) GCP project id.
location: (str) GCP compute location, such as "us-central1-b".
tpu_name: (str) The ID of the TPU node.
Returns
A TPU node object.
"""
service = discovery.build('tpu', 'v1', credentials=credentials)
name = 'projects/{}/locations/{}/nodes/{}'.format(
project, location, tpu_name)
request = service.projects().locations().nodes().get(name=name)
return request.execute()
示例6: delete_tpu
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def delete_tpu(project, location, tpu_name):
"""List existing TPU nodes in the project/location.
Args:
project: (str) GCP project id.
location: (str) GCP compute location, such as "us-central1-b".
tpu_name: (str) The ID of the TPU node.
Returns
A TPU node deletion operation object.
"""
service = discovery.build('tpu', 'v1', credentials=credentials)
name = 'projects/{}/locations/{}/nodes/{}'.format(
project, location, tpu_name)
request = service.projects().locations().nodes().delete(
name=name)
return request.execute()
示例7: file_handler
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def file_handler(update, context):
"""handles the uploaded files"""
file = context.bot.getFile(update.message.document.file_id)
file.download(update.message.document.file_name)
doc = update.message.document
service = build('drive', 'v3', credentials=getCreds(),cache_discovery=False)
filename = doc.file_name
metadata = {'name': filename}
media = MediaFileUpload(filename, chunksize=1024 * 1024, mimetype=doc.mime_type, resumable=True)
request = service.files().create(body=metadata,
media_body=media)
response = None
while response is None:
status, response = request.next_chunk()
if status:
print( "Uploaded %d%%." % int(status.progress() * 100))
context.bot.send_message(chat_id=update.effective_chat.id, text="✅ File uploaded!")
示例8: make_cloud_mlengine_request_fn
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def make_cloud_mlengine_request_fn(credentials, model_name, version):
"""Wraps function to make CloudML Engine requests with runtime args."""
def _make_cloud_mlengine_request(examples):
"""Builds and sends requests to Cloud ML Engine."""
api = discovery.build("ml", "v1", credentials=credentials)
parent = "projects/%s/models/%s/versions/%s" % (cloud.default_project(),
model_name, version)
input_data = {
"instances": [{ # pylint: disable=g-complex-comprehension
"input": {
"b64": base64.b64encode(ex.SerializeToString())
}
} for ex in examples]
}
response = api.projects().predict(body=input_data, name=parent).execute()
predictions = response["predictions"]
for prediction in predictions:
prediction["outputs"] = np.array([prediction["outputs"]])
prediction["scores"] = np.array(prediction["scores"])
return predictions
return _make_cloud_mlengine_request
示例9: main
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def main():
parser = argparse.ArgumentParser(
'build_msan_libs.py', description='MSan builder.')
parser.add_argument(
'--no-track-origins',
action='store_true',
help='Build with -fsanitize-memory-track-origins=0.')
parser.add_argument(
'command',
choices=['build_packages', 'merge'],
help='The command to run.')
args = parser.parse_args()
cloudbuild = build('cloudbuild', 'v1', cache_discovery=False)
if args.command == 'build_packages':
for package in PACKAGES:
build_body = get_build(build_steps(package, args.no_track_origins))
print(start_build(cloudbuild, build_body))
else: # merge
print(start_build(cloudbuild,
get_build(merge_steps(args.no_track_origins))))
示例10: make_cloud_mlengine_request_fn
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def make_cloud_mlengine_request_fn(credentials, model_name, version):
"""Wraps function to make CloudML Engine requests with runtime args."""
def _make_cloud_mlengine_request(examples):
"""Builds and sends requests to Cloud ML Engine."""
api = discovery.build("ml", "v1", credentials=credentials)
parent = "projects/%s/models/%s/versions/%s" % (cloud.default_project(),
model_name, version)
input_data = {
"instances": [{ # pylint: disable=g-complex-comprehension
"input": {
"b64": base64.b64encode(ex.SerializeToString())
}
} for ex in examples]
}
prediction = api.projects().predict(body=input_data, name=parent).execute()
return prediction["predictions"]
return _make_cloud_mlengine_request
示例11: get_resource_url_with_default
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def get_resource_url_with_default(self, resource, url_or_name, **kwargs):
"""
Build a GCPResourceUrl from a service's name and resource url or name.
If the url_or_name is a valid GCP resource URL, then we build the
GCPResourceUrl object by parsing this URL. If the url_or_name is its
short name, then we build the GCPResourceUrl object by constructing
the resource URL with default project, region, zone values.
"""
# If url_or_name is a valid GCP resource URL, then parse it.
if self.RESOURCE_REGEX.match(url_or_name):
return self.parse_url(url_or_name)
# Otherwise, construct resource URL with default values.
if resource not in self._resources:
log.warning('Unknown resource: %s', resource)
return None
parameter_defaults = self._parameter_defaults.copy()
parameter_defaults.update(kwargs)
parsed_url = GCPResourceUrl(resource, self._connection)
for key in self._resources[resource]['parameters']:
parsed_url.parameters[key] = parameter_defaults.get(
key, url_or_name)
return parsed_url
示例12: get_conn
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def get_conn(self):
"""
Retrieves the connection to Cloud Firestore.
:return: Google Cloud Firestore services object.
"""
if not self._conn:
http_authorized = self._authorize()
# We cannot use an Authorized Client to retrieve discovery document due to an error in the API.
# When the authorized customer will send a request to the address below
# https://www.googleapis.com/discovery/v1/apis/firestore/v1/rest
# then it will get the message below:
# > Request contains an invalid argument.
# At the same time, the Non-Authorized Client has no problems.
non_authorized_conn = build("firestore", self.api_version, cache_discovery=False)
self._conn = build_from_document(
non_authorized_conn._rootDesc, # pylint: disable=protected-access
http=http_authorized
)
return self._conn
示例13: get_pubsub_client
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def get_pubsub_client():
"""Get a pubsub client from the API."""
return discovery.build('pubsub', 'v1', credentials=CREDENTIALS)
示例14: __init__
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def __init__(self):
Plugin.__init__(self)
self.sqladmin = discovery.build(
'sqladmin', 'v1beta4', credentials=CREDENTIALS)
self.batch = self.sqladmin.new_batch_http_request(
callback=self.batch_callback)
示例15: __init__
# 需要导入模块: from googleapiclient import discovery [as 别名]
# 或者: from googleapiclient.discovery import build [as 别名]
def __init__(self):
Plugin.__init__(self)
self.storage = discovery.build(
'storage', 'v1', credentials=CREDENTIALS)
self.batch = self.storage.new_batch_http_request(
callback=self.batch_callback)