google-cloud-spanner 3.55.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. google/cloud/spanner.py +47 -0
  2. google/cloud/spanner_admin_database_v1/__init__.py +146 -0
  3. google/cloud/spanner_admin_database_v1/gapic_metadata.json +418 -0
  4. google/cloud/spanner_admin_database_v1/gapic_version.py +16 -0
  5. google/cloud/spanner_admin_database_v1/py.typed +2 -0
  6. google/cloud/spanner_admin_database_v1/services/__init__.py +15 -0
  7. google/cloud/spanner_admin_database_v1/services/database_admin/__init__.py +22 -0
  8. google/cloud/spanner_admin_database_v1/services/database_admin/async_client.py +4097 -0
  9. google/cloud/spanner_admin_database_v1/services/database_admin/client.py +4602 -0
  10. google/cloud/spanner_admin_database_v1/services/database_admin/pagers.py +989 -0
  11. google/cloud/spanner_admin_database_v1/services/database_admin/transports/__init__.py +38 -0
  12. google/cloud/spanner_admin_database_v1/services/database_admin/transports/base.py +820 -0
  13. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc.py +1303 -0
  14. google/cloud/spanner_admin_database_v1/services/database_admin/transports/grpc_asyncio.py +1688 -0
  15. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest.py +6512 -0
  16. google/cloud/spanner_admin_database_v1/services/database_admin/transports/rest_base.py +1650 -0
  17. google/cloud/spanner_admin_database_v1/types/__init__.py +144 -0
  18. google/cloud/spanner_admin_database_v1/types/backup.py +1106 -0
  19. google/cloud/spanner_admin_database_v1/types/backup_schedule.py +369 -0
  20. google/cloud/spanner_admin_database_v1/types/common.py +180 -0
  21. google/cloud/spanner_admin_database_v1/types/spanner_database_admin.py +1303 -0
  22. google/cloud/spanner_admin_instance_v1/__init__.py +110 -0
  23. google/cloud/spanner_admin_instance_v1/gapic_metadata.json +343 -0
  24. google/cloud/spanner_admin_instance_v1/gapic_version.py +16 -0
  25. google/cloud/spanner_admin_instance_v1/py.typed +2 -0
  26. google/cloud/spanner_admin_instance_v1/services/__init__.py +15 -0
  27. google/cloud/spanner_admin_instance_v1/services/instance_admin/__init__.py +22 -0
  28. google/cloud/spanner_admin_instance_v1/services/instance_admin/async_client.py +3466 -0
  29. google/cloud/spanner_admin_instance_v1/services/instance_admin/client.py +3881 -0
  30. google/cloud/spanner_admin_instance_v1/services/instance_admin/pagers.py +856 -0
  31. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/__init__.py +38 -0
  32. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/base.py +545 -0
  33. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc.py +1347 -0
  34. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/grpc_asyncio.py +1539 -0
  35. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest.py +4834 -0
  36. google/cloud/spanner_admin_instance_v1/services/instance_admin/transports/rest_base.py +1198 -0
  37. google/cloud/spanner_admin_instance_v1/types/__init__.py +104 -0
  38. google/cloud/spanner_admin_instance_v1/types/common.py +99 -0
  39. google/cloud/spanner_admin_instance_v1/types/spanner_instance_admin.py +2375 -0
  40. google/cloud/spanner_dbapi/__init__.py +93 -0
  41. google/cloud/spanner_dbapi/_helpers.py +113 -0
  42. google/cloud/spanner_dbapi/batch_dml_executor.py +135 -0
  43. google/cloud/spanner_dbapi/checksum.py +80 -0
  44. google/cloud/spanner_dbapi/client_side_statement_executor.py +140 -0
  45. google/cloud/spanner_dbapi/client_side_statement_parser.py +106 -0
  46. google/cloud/spanner_dbapi/connection.py +818 -0
  47. google/cloud/spanner_dbapi/cursor.py +609 -0
  48. google/cloud/spanner_dbapi/exceptions.py +172 -0
  49. google/cloud/spanner_dbapi/parse_utils.py +392 -0
  50. google/cloud/spanner_dbapi/parsed_statement.py +63 -0
  51. google/cloud/spanner_dbapi/parser.py +258 -0
  52. google/cloud/spanner_dbapi/partition_helper.py +41 -0
  53. google/cloud/spanner_dbapi/transaction_helper.py +294 -0
  54. google/cloud/spanner_dbapi/types.py +106 -0
  55. google/cloud/spanner_dbapi/utils.py +147 -0
  56. google/cloud/spanner_dbapi/version.py +20 -0
  57. google/cloud/spanner_v1/__init__.py +154 -0
  58. google/cloud/spanner_v1/_helpers.py +751 -0
  59. google/cloud/spanner_v1/_opentelemetry_tracing.py +165 -0
  60. google/cloud/spanner_v1/backup.py +397 -0
  61. google/cloud/spanner_v1/batch.py +433 -0
  62. google/cloud/spanner_v1/client.py +538 -0
  63. google/cloud/spanner_v1/data_types.py +350 -0
  64. google/cloud/spanner_v1/database.py +1968 -0
  65. google/cloud/spanner_v1/database_sessions_manager.py +249 -0
  66. google/cloud/spanner_v1/gapic_metadata.json +268 -0
  67. google/cloud/spanner_v1/gapic_version.py +16 -0
  68. google/cloud/spanner_v1/instance.py +735 -0
  69. google/cloud/spanner_v1/keyset.py +193 -0
  70. google/cloud/spanner_v1/merged_result_set.py +146 -0
  71. google/cloud/spanner_v1/metrics/constants.py +71 -0
  72. google/cloud/spanner_v1/metrics/metrics_capture.py +75 -0
  73. google/cloud/spanner_v1/metrics/metrics_exporter.py +384 -0
  74. google/cloud/spanner_v1/metrics/metrics_interceptor.py +156 -0
  75. google/cloud/spanner_v1/metrics/metrics_tracer.py +588 -0
  76. google/cloud/spanner_v1/metrics/metrics_tracer_factory.py +328 -0
  77. google/cloud/spanner_v1/metrics/spanner_metrics_tracer_factory.py +172 -0
  78. google/cloud/spanner_v1/param_types.py +110 -0
  79. google/cloud/spanner_v1/pool.py +813 -0
  80. google/cloud/spanner_v1/py.typed +2 -0
  81. google/cloud/spanner_v1/request_id_header.py +64 -0
  82. google/cloud/spanner_v1/services/__init__.py +15 -0
  83. google/cloud/spanner_v1/services/spanner/__init__.py +22 -0
  84. google/cloud/spanner_v1/services/spanner/async_client.py +2205 -0
  85. google/cloud/spanner_v1/services/spanner/client.py +2624 -0
  86. google/cloud/spanner_v1/services/spanner/pagers.py +196 -0
  87. google/cloud/spanner_v1/services/spanner/transports/__init__.py +38 -0
  88. google/cloud/spanner_v1/services/spanner/transports/base.py +520 -0
  89. google/cloud/spanner_v1/services/spanner/transports/grpc.py +911 -0
  90. google/cloud/spanner_v1/services/spanner/transports/grpc_asyncio.py +1144 -0
  91. google/cloud/spanner_v1/services/spanner/transports/rest.py +3468 -0
  92. google/cloud/spanner_v1/services/spanner/transports/rest_base.py +981 -0
  93. google/cloud/spanner_v1/session.py +631 -0
  94. google/cloud/spanner_v1/session_options.py +133 -0
  95. google/cloud/spanner_v1/snapshot.py +1057 -0
  96. google/cloud/spanner_v1/streamed.py +402 -0
  97. google/cloud/spanner_v1/table.py +181 -0
  98. google/cloud/spanner_v1/testing/__init__.py +0 -0
  99. google/cloud/spanner_v1/testing/database_test.py +121 -0
  100. google/cloud/spanner_v1/testing/interceptors.py +118 -0
  101. google/cloud/spanner_v1/testing/mock_database_admin.py +38 -0
  102. google/cloud/spanner_v1/testing/mock_spanner.py +261 -0
  103. google/cloud/spanner_v1/testing/spanner_database_admin_pb2_grpc.py +1267 -0
  104. google/cloud/spanner_v1/testing/spanner_pb2_grpc.py +882 -0
  105. google/cloud/spanner_v1/transaction.py +747 -0
  106. google/cloud/spanner_v1/types/__init__.py +118 -0
  107. google/cloud/spanner_v1/types/commit_response.py +94 -0
  108. google/cloud/spanner_v1/types/keys.py +248 -0
  109. google/cloud/spanner_v1/types/mutation.py +201 -0
  110. google/cloud/spanner_v1/types/query_plan.py +220 -0
  111. google/cloud/spanner_v1/types/result_set.py +379 -0
  112. google/cloud/spanner_v1/types/spanner.py +1815 -0
  113. google/cloud/spanner_v1/types/transaction.py +818 -0
  114. google/cloud/spanner_v1/types/type.py +288 -0
  115. google_cloud_spanner-3.55.0.dist-info/LICENSE +202 -0
  116. google_cloud_spanner-3.55.0.dist-info/METADATA +318 -0
  117. google_cloud_spanner-3.55.0.dist-info/RECORD +119 -0
  118. google_cloud_spanner-3.55.0.dist-info/WHEEL +5 -0
  119. google_cloud_spanner-3.55.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,538 @@
1
+ # Copyright 2016 Google LLC All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Parent client for calling the Cloud Spanner API.
16
+
17
+ This is the base from which all interactions with the API occur.
18
+
19
+ In the hierarchy of API concepts
20
+
21
+ * a :class:`~google.cloud.spanner_v1.client.Client` owns an
22
+ :class:`~google.cloud.spanner_v1.instance.Instance`
23
+ * a :class:`~google.cloud.spanner_v1.instance.Instance` owns a
24
+ :class:`~google.cloud.spanner_v1.database.Database`
25
+ """
26
+ import grpc
27
+ import os
28
+ import warnings
29
+
30
+ from google.api_core.gapic_v1 import client_info
31
+ from google.auth.credentials import AnonymousCredentials
32
+ import google.api_core.client_options
33
+ from google.cloud.client import ClientWithProject
34
+ from typing import Optional
35
+
36
+
37
+ from google.cloud.spanner_admin_database_v1 import DatabaseAdminClient
38
+ from google.cloud.spanner_admin_database_v1.services.database_admin.transports.grpc import (
39
+ DatabaseAdminGrpcTransport,
40
+ )
41
+ from google.cloud.spanner_admin_instance_v1 import InstanceAdminClient
42
+ from google.cloud.spanner_admin_instance_v1.services.instance_admin.transports.grpc import (
43
+ InstanceAdminGrpcTransport,
44
+ )
45
+ from google.cloud.spanner_admin_instance_v1 import ListInstanceConfigsRequest
46
+ from google.cloud.spanner_admin_instance_v1 import ListInstancesRequest
47
+ from google.cloud.spanner_v1 import __version__
48
+ from google.cloud.spanner_v1 import ExecuteSqlRequest
49
+ from google.cloud.spanner_v1 import DefaultTransactionOptions
50
+ from google.cloud.spanner_v1._helpers import _merge_query_options
51
+ from google.cloud.spanner_v1._helpers import _metadata_with_prefix
52
+ from google.cloud.spanner_v1.instance import Instance
53
+ from google.cloud.spanner_v1.metrics.constants import (
54
+ ENABLE_SPANNER_METRICS_ENV_VAR,
55
+ METRIC_EXPORT_INTERVAL_MS,
56
+ )
57
+ from google.cloud.spanner_v1.metrics.spanner_metrics_tracer_factory import (
58
+ SpannerMetricsTracerFactory,
59
+ )
60
+ from google.cloud.spanner_v1.metrics.metrics_exporter import (
61
+ CloudMonitoringMetricsExporter,
62
+ )
63
+
64
+ try:
65
+ from opentelemetry import metrics
66
+ from opentelemetry.sdk.metrics import MeterProvider
67
+ from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
68
+
69
+ HAS_GOOGLE_CLOUD_MONITORING_INSTALLED = True
70
+ except ImportError: # pragma: NO COVER
71
+ HAS_GOOGLE_CLOUD_MONITORING_INSTALLED = False
72
+
73
+ from google.cloud.spanner_v1._helpers import AtomicCounter
74
+
75
+ _CLIENT_INFO = client_info.ClientInfo(client_library_version=__version__)
76
+ EMULATOR_ENV_VAR = "SPANNER_EMULATOR_HOST"
77
+ ENABLE_BUILTIN_METRICS_ENV_VAR = "SPANNER_ENABLE_BUILTIN_METRICS"
78
+ _EMULATOR_HOST_HTTP_SCHEME = (
79
+ "%s contains a http scheme. When used with a scheme it may cause gRPC's "
80
+ "DNS resolver to endlessly attempt to resolve. %s is intended to be used "
81
+ "without a scheme: ex %s=localhost:8080."
82
+ ) % ((EMULATOR_ENV_VAR,) * 3)
83
+ SPANNER_ADMIN_SCOPE = "https://www.googleapis.com/auth/spanner.admin"
84
+ OPTIMIZER_VERSION_ENV_VAR = "SPANNER_OPTIMIZER_VERSION"
85
+ OPTIMIZER_STATISITCS_PACKAGE_ENV_VAR = "SPANNER_OPTIMIZER_STATISTICS_PACKAGE"
86
+
87
+
88
+ def _get_spanner_emulator_host():
89
+ return os.getenv(EMULATOR_ENV_VAR)
90
+
91
+
92
+ def _get_spanner_optimizer_version():
93
+ return os.getenv(OPTIMIZER_VERSION_ENV_VAR, "")
94
+
95
+
96
+ def _get_spanner_optimizer_statistics_package():
97
+ return os.getenv(OPTIMIZER_STATISITCS_PACKAGE_ENV_VAR, "")
98
+
99
+
100
+ def _get_spanner_enable_builtin_metrics():
101
+ return os.getenv(ENABLE_SPANNER_METRICS_ENV_VAR) == "true"
102
+
103
+
104
+ class Client(ClientWithProject):
105
+ """Client for interacting with Cloud Spanner API.
106
+
107
+ .. note::
108
+
109
+ Since the Cloud Spanner API requires the gRPC transport, no
110
+ ``_http`` argument is accepted by this class.
111
+
112
+ :type project: :class:`str` or :func:`unicode <unicode>`
113
+ :param project: (Optional) The ID of the project which owns the
114
+ instances, tables and data. If not provided, will
115
+ attempt to determine from the environment.
116
+
117
+ :type credentials:
118
+ :class:`Credentials <google.auth.credentials.Credentials>` or
119
+ :data:`NoneType <types.NoneType>`
120
+ :param credentials: (Optional) The authorization credentials to attach to requests.
121
+ These credentials identify this application to the service.
122
+ If none are specified, the client will attempt to ascertain
123
+ the credentials from the environment.
124
+
125
+ :type client_info: :class:`~google.api_core.gapic_v1.client_info.ClientInfo`
126
+ :param client_info:
127
+ (Optional) The client info used to send a user-agent string along with
128
+ API requests. If ``None``, then default info will be used. Generally,
129
+ you only need to set this if you're developing your own library or
130
+ partner tool.
131
+
132
+ :type client_options: :class:`~google.api_core.client_options.ClientOptions`
133
+ or :class:`dict`
134
+ :param client_options: (Optional) Client options used to set user options
135
+ on the client. API Endpoint should be set through client_options.
136
+
137
+ :type query_options:
138
+ :class:`~google.cloud.spanner_v1.types.ExecuteSqlRequest.QueryOptions`
139
+ or :class:`dict`
140
+ :param query_options:
141
+ (Optional) Query optimizer configuration to use for the given query.
142
+ If a dict is provided, it must be of the same form as the protobuf
143
+ message :class:`~google.cloud.spanner_v1.types.QueryOptions`
144
+
145
+ :type route_to_leader_enabled: boolean
146
+ :param route_to_leader_enabled:
147
+ (Optional) Default True. Set route_to_leader_enabled as False to
148
+ disable leader aware routing. Disabling leader aware routing would
149
+ route all requests in RW/PDML transactions to the closest region.
150
+
151
+ :type directed_read_options: :class:`~google.cloud.spanner_v1.DirectedReadOptions`
152
+ or :class:`dict`
153
+ :param directed_read_options: (Optional) Client options used to set the directed_read_options
154
+ for all ReadRequests and ExecuteSqlRequests that indicates which replicas
155
+ or regions should be used for non-transactional reads or queries.
156
+
157
+ :type observability_options: dict (str -> any) or None
158
+ :param observability_options: (Optional) the configuration to control
159
+ the tracer's behavior.
160
+ tracer_provider is the injected tracer provider
161
+ enable_extended_tracing: :type:boolean when set to true will allow for
162
+ spans that issue SQL statements to be annotated with SQL.
163
+ Default `True`, please set it to `False` to turn it off
164
+ or you can use the environment variable `SPANNER_ENABLE_EXTENDED_TRACING=<boolean>`
165
+ to control it.
166
+ enable_end_to_end_tracing: :type:boolean when set to true will allow for spans from Spanner server side.
167
+ Default `False`, please set it to `True` to turn it on
168
+ or you can use the environment variable `SPANNER_ENABLE_END_TO_END_TRACING=<boolean>`
169
+ to control it.
170
+
171
+ :type default_transaction_options: :class:`~google.cloud.spanner_v1.DefaultTransactionOptions`
172
+ or :class:`dict`
173
+ :param default_transaction_options: (Optional) Default options to use for all transactions.
174
+
175
+ :raises: :class:`ValueError <exceptions.ValueError>` if both ``read_only``
176
+ and ``admin`` are :data:`True`
177
+ """
178
+
179
+ _instance_admin_api = None
180
+ _database_admin_api = None
181
+ _SET_PROJECT = True # Used by from_service_account_json()
182
+
183
+ SCOPE = (SPANNER_ADMIN_SCOPE,)
184
+ """The scopes required for Google Cloud Spanner."""
185
+
186
+ NTH_CLIENT = AtomicCounter()
187
+
188
+ def __init__(
189
+ self,
190
+ project=None,
191
+ credentials=None,
192
+ client_info=_CLIENT_INFO,
193
+ client_options=None,
194
+ query_options=None,
195
+ route_to_leader_enabled=True,
196
+ directed_read_options=None,
197
+ observability_options=None,
198
+ default_transaction_options: Optional[DefaultTransactionOptions] = None,
199
+ ):
200
+ self._emulator_host = _get_spanner_emulator_host()
201
+
202
+ if client_options and type(client_options) is dict:
203
+ self._client_options = google.api_core.client_options.from_dict(
204
+ client_options
205
+ )
206
+ else:
207
+ self._client_options = client_options
208
+
209
+ if self._emulator_host:
210
+ credentials = AnonymousCredentials()
211
+ elif isinstance(credentials, AnonymousCredentials):
212
+ self._emulator_host = self._client_options.api_endpoint
213
+
214
+ # NOTE: This API has no use for the _http argument, but sending it
215
+ # will have no impact since the _http() @property only lazily
216
+ # creates a working HTTP object.
217
+ super(Client, self).__init__(
218
+ project=project,
219
+ credentials=credentials,
220
+ client_options=client_options,
221
+ _http=None,
222
+ )
223
+ self._client_info = client_info
224
+
225
+ env_query_options = ExecuteSqlRequest.QueryOptions(
226
+ optimizer_version=_get_spanner_optimizer_version(),
227
+ optimizer_statistics_package=_get_spanner_optimizer_statistics_package(),
228
+ )
229
+
230
+ # Environment flag config has higher precedence than application config.
231
+ self._query_options = _merge_query_options(query_options, env_query_options)
232
+
233
+ if self._emulator_host is not None and (
234
+ "http://" in self._emulator_host or "https://" in self._emulator_host
235
+ ):
236
+ warnings.warn(_EMULATOR_HOST_HTTP_SCHEME)
237
+ # Check flag to enable Spanner builtin metrics
238
+ if (
239
+ _get_spanner_enable_builtin_metrics()
240
+ and HAS_GOOGLE_CLOUD_MONITORING_INSTALLED
241
+ ):
242
+ meter_provider = metrics.NoOpMeterProvider()
243
+ if not _get_spanner_emulator_host():
244
+ meter_provider = MeterProvider(
245
+ metric_readers=[
246
+ PeriodicExportingMetricReader(
247
+ CloudMonitoringMetricsExporter(
248
+ project_id=project, credentials=credentials
249
+ ),
250
+ export_interval_millis=METRIC_EXPORT_INTERVAL_MS,
251
+ )
252
+ ]
253
+ )
254
+ metrics.set_meter_provider(meter_provider)
255
+ SpannerMetricsTracerFactory()
256
+ else:
257
+ SpannerMetricsTracerFactory(enabled=False)
258
+
259
+ self._route_to_leader_enabled = route_to_leader_enabled
260
+ self._directed_read_options = directed_read_options
261
+ self._observability_options = observability_options
262
+ if default_transaction_options is None:
263
+ default_transaction_options = DefaultTransactionOptions()
264
+ elif not isinstance(default_transaction_options, DefaultTransactionOptions):
265
+ raise TypeError(
266
+ "default_transaction_options must be an instance of DefaultTransactionOptions"
267
+ )
268
+ self._default_transaction_options = default_transaction_options
269
+ self._nth_client_id = Client.NTH_CLIENT.increment()
270
+ self._nth_request = AtomicCounter(0)
271
+
272
+ @property
273
+ def _next_nth_request(self):
274
+ return self._nth_request.increment()
275
+
276
+ @property
277
+ def credentials(self):
278
+ """Getter for client's credentials.
279
+
280
+ :rtype:
281
+ :class:`Credentials <google.auth.credentials.Credentials>`
282
+ :returns: The credentials stored on the client.
283
+ """
284
+ return self._credentials
285
+
286
+ @property
287
+ def project_name(self):
288
+ """Project name to be used with Spanner APIs.
289
+
290
+ .. note::
291
+
292
+ This property will not change if ``project`` does not, but the
293
+ return value is not cached.
294
+
295
+ The project name is of the form
296
+
297
+ ``"projects/{project}"``
298
+
299
+ :rtype: str
300
+ :returns: The project name to be used with the Cloud Spanner Admin
301
+ API RPC service.
302
+ """
303
+ return "projects/" + self.project
304
+
305
+ @property
306
+ def instance_admin_api(self):
307
+ """Helper for session-related API calls."""
308
+ if self._instance_admin_api is None:
309
+ if self._emulator_host is not None:
310
+ transport = InstanceAdminGrpcTransport(
311
+ channel=grpc.insecure_channel(target=self._emulator_host)
312
+ )
313
+ self._instance_admin_api = InstanceAdminClient(
314
+ client_info=self._client_info,
315
+ client_options=self._client_options,
316
+ transport=transport,
317
+ )
318
+ else:
319
+ self._instance_admin_api = InstanceAdminClient(
320
+ credentials=self.credentials,
321
+ client_info=self._client_info,
322
+ client_options=self._client_options,
323
+ )
324
+ return self._instance_admin_api
325
+
326
+ @property
327
+ def database_admin_api(self):
328
+ """Helper for session-related API calls."""
329
+ if self._database_admin_api is None:
330
+ if self._emulator_host is not None:
331
+ transport = DatabaseAdminGrpcTransport(
332
+ channel=grpc.insecure_channel(target=self._emulator_host)
333
+ )
334
+ self._database_admin_api = DatabaseAdminClient(
335
+ client_info=self._client_info,
336
+ client_options=self._client_options,
337
+ transport=transport,
338
+ )
339
+ else:
340
+ self._database_admin_api = DatabaseAdminClient(
341
+ credentials=self.credentials,
342
+ client_info=self._client_info,
343
+ client_options=self._client_options,
344
+ )
345
+ return self._database_admin_api
346
+
347
+ @property
348
+ def route_to_leader_enabled(self):
349
+ """Getter for if read-write or pdml requests will be routed to leader.
350
+
351
+ :rtype: boolean
352
+ :returns: If read-write requests will be routed to leader.
353
+ """
354
+ return self._route_to_leader_enabled
355
+
356
+ @property
357
+ def observability_options(self):
358
+ """Getter for observability_options.
359
+
360
+ :rtype: dict
361
+ :returns: The configured observability_options if set.
362
+ """
363
+ return self._observability_options
364
+
365
+ @property
366
+ def default_transaction_options(self):
367
+ """Getter for default_transaction_options.
368
+
369
+ :rtype:
370
+ :class:`~google.cloud.spanner_v1.DefaultTransactionOptions`
371
+ or :class:`dict`
372
+ :returns: The default transaction options that are used by this client for all transactions.
373
+ """
374
+ return self._default_transaction_options
375
+
376
+ @property
377
+ def directed_read_options(self):
378
+ """Getter for directed_read_options.
379
+
380
+ :rtype:
381
+ :class:`~google.cloud.spanner_v1.DirectedReadOptions`
382
+ or :class:`dict`
383
+ :returns: The directed_read_options for the client.
384
+ """
385
+ return self._directed_read_options
386
+
387
+ def copy(self):
388
+ """Make a copy of this client.
389
+
390
+ Copies the local data stored as simple types but does not copy the
391
+ current state of any open connections with the Cloud Bigtable API.
392
+
393
+ :rtype: :class:`.Client`
394
+ :returns: A copy of the current client.
395
+ """
396
+ return self.__class__(project=self.project, credentials=self._credentials)
397
+
398
+ def list_instance_configs(self, page_size=None):
399
+ """List available instance configurations for the client's project.
400
+
401
+ .. _RPC docs: https://cloud.google.com/spanner/docs/reference/rpc/\
402
+ google.spanner.admin.instance.v1#google.spanner.admin.\
403
+ instance.v1.InstanceAdmin.ListInstanceConfigs
404
+
405
+ See `RPC docs`_.
406
+
407
+ :type page_size: int
408
+ :param page_size:
409
+ Optional. The maximum number of configs in each page of results
410
+ from this request. Non-positive values are ignored. Defaults
411
+ to a sensible value set by the API.
412
+
413
+ :rtype: :class:`~google.api_core.page_iterator.Iterator`
414
+ :returns:
415
+ Iterator of
416
+ :class:`~google.cloud.spanner_admin_instance_v1.types.InstanceConfig`
417
+ resources within the client's project.
418
+ """
419
+ metadata = _metadata_with_prefix(self.project_name)
420
+ request = ListInstanceConfigsRequest(
421
+ parent=self.project_name, page_size=page_size
422
+ )
423
+ page_iter = self.instance_admin_api.list_instance_configs(
424
+ request=request, metadata=metadata
425
+ )
426
+ return page_iter
427
+
428
+ def instance(
429
+ self,
430
+ instance_id,
431
+ configuration_name=None,
432
+ display_name=None,
433
+ node_count=None,
434
+ labels=None,
435
+ processing_units=None,
436
+ ):
437
+ """Factory to create a instance associated with this client.
438
+
439
+ :type instance_id: str
440
+ :param instance_id: The ID of the instance.
441
+
442
+ :type configuration_name: string
443
+ :param configuration_name:
444
+ (Optional) Name of the instance configuration used to set up the
445
+ instance's cluster, in the form:
446
+ ``projects/<project>/instanceConfigs/``
447
+ ``<config>``.
448
+ **Required** for instances which do not yet exist.
449
+
450
+ :type display_name: str
451
+ :param display_name: (Optional) The display name for the instance in
452
+ the Cloud Console UI. (Must be between 4 and 30
453
+ characters.) If this value is not set in the
454
+ constructor, will fall back to the instance ID.
455
+
456
+ :type node_count: int
457
+ :param node_count: (Optional) The number of nodes in the instance's
458
+ cluster; used to set up the instance's cluster.
459
+
460
+ :type processing_units: int
461
+ :param processing_units: (Optional) The number of processing units
462
+ allocated to this instance.
463
+
464
+ :type labels: dict (str -> str) or None
465
+ :param labels: (Optional) User-assigned labels for this instance.
466
+
467
+ :rtype: :class:`~google.cloud.spanner_v1.instance.Instance`
468
+ :returns: an instance owned by this client.
469
+ """
470
+ return Instance(
471
+ instance_id,
472
+ self,
473
+ configuration_name,
474
+ node_count,
475
+ display_name,
476
+ self._emulator_host,
477
+ labels,
478
+ processing_units,
479
+ )
480
+
481
+ def list_instances(self, filter_="", page_size=None):
482
+ """List instances for the client's project.
483
+
484
+ See
485
+ https://cloud.google.com/spanner/reference/rpc/google.spanner.admin.database.v1#google.spanner.admin.database.v1.InstanceAdmin.ListInstances
486
+
487
+ :type filter_: string
488
+ :param filter_: (Optional) Filter to select instances listed. See
489
+ the ``ListInstancesRequest`` docs above for examples.
490
+
491
+ :type page_size: int
492
+ :param page_size:
493
+ Optional. The maximum number of instances in each page of results
494
+ from this request. Non-positive values are ignored. Defaults
495
+ to a sensible value set by the API.
496
+
497
+ :rtype: :class:`~google.api_core.page_iterator.Iterator`
498
+ :returns:
499
+ Iterator of :class:`~google.cloud.spanner_admin_instance_v1.types.Instance`
500
+ resources within the client's project.
501
+ """
502
+ metadata = _metadata_with_prefix(self.project_name)
503
+ request = ListInstancesRequest(
504
+ parent=self.project_name, filter=filter_, page_size=page_size
505
+ )
506
+ page_iter = self.instance_admin_api.list_instances(
507
+ request=request, metadata=metadata
508
+ )
509
+ return page_iter
510
+
511
+ @directed_read_options.setter
512
+ def directed_read_options(self, directed_read_options):
513
+ """Sets directed_read_options for the client
514
+ :type directed_read_options: :class:`~google.cloud.spanner_v1.DirectedReadOptions`
515
+ or :class:`dict`
516
+ :param directed_read_options: Client options used to set the directed_read_options
517
+ for all ReadRequests and ExecuteSqlRequests that indicates which replicas
518
+ or regions should be used for non-transactional reads or queries.
519
+ """
520
+ self._directed_read_options = directed_read_options
521
+
522
+ @default_transaction_options.setter
523
+ def default_transaction_options(
524
+ self, default_transaction_options: DefaultTransactionOptions
525
+ ):
526
+ """Sets default_transaction_options for the client
527
+ :type default_transaction_options: :class:`~google.cloud.spanner_v1.DefaultTransactionOptions`
528
+ or :class:`dict`
529
+ :param default_transaction_options: Default options to use for transactions.
530
+ """
531
+ if default_transaction_options is None:
532
+ default_transaction_options = DefaultTransactionOptions()
533
+ elif not isinstance(default_transaction_options, DefaultTransactionOptions):
534
+ raise TypeError(
535
+ "default_transaction_options must be an instance of DefaultTransactionOptions"
536
+ )
537
+
538
+ self._default_transaction_options = default_transaction_options