Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the Cloud ML service account programmatically in Python?

The Cloud ML instructions show how to obtain the service account using shell commands. How can I do this programmatically in Python? e.g. in Datalab?

like image 585
Jeremy Lewi Avatar asked Nov 16 '25 11:11

Jeremy Lewi


1 Answers

You can use Google Cloud's Python client libraries to issue the getConfig request.

from googleapiclient import discovery
from googleapiclient import http
from oauth2client.client import GoogleCredentials

credentials = GoogleCredentials.get_application_default()

ml_client = discovery.build(
    'ml',
    'v1beta1',
    requestBuilder=http.HttpRequest,
    credentials=credentials)
p = ml_client.projects()
config = p.getConfig(name="projects/my-project").execute()
SERVICE_ACCOUNT = config["serviceAccount"]
like image 180
Jeremy Lewi Avatar answered Nov 19 '25 09:11

Jeremy Lewi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!