@@ -357,10 +357,13 @@ def connect(
357357 instances, tables and data. If not provided, will
358358 attempt to determine from the environment.
359359
360- :type credentials: :class:`~google.auth.credentials.Credentials`
360+ :type credentials: Union[ :class:`~google.auth.credentials.Credentials`, str]
361361 :param credentials: (Optional) The authorization credentials to attach to
362362 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
364367 attempt to ascertain the credentials from the
365368 environment.
366369
@@ -384,9 +387,14 @@ def connect(
384387 user_agent = user_agent or DEFAULT_USER_AGENT , python_version = PY_VERSION
385388 )
386389
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+ )
390398
391399 instance = client .instance (instance_id )
392400 if not instance .exists ():
0 commit comments