@@ -357,10 +357,13 @@ def connect(
357
357
instances, tables and data. If not provided, will
358
358
attempt to determine from the environment.
359
359
360
- :type credentials: :class:`~google.auth.credentials.Credentials`
360
+ :type credentials: Union[ :class:`~google.auth.credentials.Credentials`, str]
361
361
:param credentials: (Optional) The authorization credentials to attach to
362
362
requests. These credentials identify this application
363
- to the service. If none are specified, the client will
363
+ to the service. These credentials may be specified as
364
+ a file path indicating where to retrieve the service
365
+ account JSON for the credentials to connect to
366
+ Cloud Spanner. If none are specified, the client will
364
367
attempt to ascertain the credentials from the
365
368
environment.
366
369
@@ -384,9 +387,14 @@ def connect(
384
387
user_agent = user_agent or DEFAULT_USER_AGENT , python_version = PY_VERSION
385
388
)
386
389
387
- client = spanner .Client (
388
- project = project , credentials = credentials , client_info = client_info
389
- )
390
+ if isinstance (credentials , str ):
391
+ client = spanner .Client .from_service_account_json (
392
+ credentials , project = project , client_info = client_info
393
+ )
394
+ else :
395
+ client = spanner .Client (
396
+ project = project , credentials = credentials , client_info = client_info
397
+ )
390
398
391
399
instance = client .instance (instance_id )
392
400
if not instance .exists ():
0 commit comments