Skip to content

Commit 2900354

Browse files
committed
feat: expose async client
Expose a property that returns the underlying async Spanner gRPC client.
1 parent 5e8ca94 commit 2900354

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

google/cloud/spanner_v1/database.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
from google.cloud.spanner_v1 import TransactionSelector
4848
from google.cloud.spanner_v1 import TransactionOptions
4949
from google.cloud.spanner_v1 import RequestOptions
50+
from google.cloud.spanner_v1 import SpannerAsyncClient
5051
from google.cloud.spanner_v1 import SpannerClient
5152
from google.cloud.spanner_v1._helpers import _merge_query_options
5253
from google.cloud.spanner_v1._helpers import (
@@ -143,6 +144,7 @@ class Database(object):
143144
"""
144145

145146
_spanner_api = None
147+
_spanner_async_api: SpannerAsyncClient = None
146148

147149
def __init__(
148150
self,
@@ -438,6 +440,28 @@ def spanner_api(self):
438440
)
439441
return self._spanner_api
440442

443+
@property
444+
def spanner_async_api(self):
445+
if self._spanner_async_api is None:
446+
client_info = self._instance._client._client_info
447+
client_options = self._instance._client._client_options
448+
if self._instance.emulator_host is not None:
449+
channel = grpc.aio.insecure_channel(target=self._instance.emulator_host)
450+
transport = SpannerGrpcTransport(channel=channel)
451+
self._spanner_async_api = SpannerAsyncClient(
452+
client_info=client_info, transport=transport
453+
)
454+
return self._spanner_async_api
455+
credentials = self._instance._client.credentials
456+
if isinstance(credentials, google.auth.credentials.Scoped):
457+
credentials = credentials.with_scopes((SPANNER_DATA_SCOPE,))
458+
self._spanner_async_api = SpannerAsyncClient(
459+
credentials=credentials,
460+
client_info=client_info,
461+
client_options=client_options,
462+
)
463+
return self._spanner_async_api
464+
441465
def __eq__(self, other):
442466
if not isinstance(other, self.__class__):
443467
return NotImplemented

noxfile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
ISORT_VERSION = "isort==5.11.0"
3333
LINT_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"]
3434

35-
DEFAULT_PYTHON_VERSION = "3.8"
35+
DEFAULT_PYTHON_VERSION = "3.12"
3636

3737
UNIT_TEST_PYTHON_VERSIONS: List[str] = [
3838
"3.7",

0 commit comments

Comments
 (0)