diff --git a/google/cloud/bigtable_v2/services/bigtable/async_client.py b/google/cloud/bigtable_v2/services/bigtable/async_client.py index 0a9442287..7240f24c9 100644 --- a/google/cloud/bigtable_v2/services/bigtable/async_client.py +++ b/google/cloud/bigtable_v2/services/bigtable/async_client.py @@ -65,7 +65,42 @@ _LOGGER = std_logging.getLogger(__name__) -class BigtableAsyncClient: +class BigtableAsyncClientMeta(type): + """Metaclass for the Bigtable async client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + + _transport_registry = OrderedDict() # type: Dict[str, Type[BigtableTransport]] + _transport_registry["grpc_asyncio"] = BigtableGrpcAsyncIOTransport + + def get_transport_class( + cls, + label: Optional[str] = None, + ) -> Type[BigtableTransport]: + """Returns an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + + + +class BigtableAsyncClient(metaclass=BigtableAsyncClientMeta): """Service for reading from and writing to existing Bigtable tables. """ @@ -264,9 +299,10 @@ def __init__( google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport creation failed for any reason. """ + transport_cls = BigtableAsyncClient.get_transport_class(transport) self._client = BigtableClient( credentials=credentials, - transport=transport, + transport=transport_cls, client_options=client_options, client_info=client_info, ) diff --git a/google/cloud/bigtable_v2/services/bigtable/client.py b/google/cloud/bigtable_v2/services/bigtable/client.py index 5eb6ba894..e5812952f 100644 --- a/google/cloud/bigtable_v2/services/bigtable/client.py +++ b/google/cloud/bigtable_v2/services/bigtable/client.py @@ -82,7 +82,6 @@ class BigtableClientMeta(type): _transport_registry = OrderedDict() # type: Dict[str, Type[BigtableTransport]] _transport_registry["grpc"] = BigtableGrpcTransport - _transport_registry["grpc_asyncio"] = BigtableGrpcAsyncIOTransport _transport_registry["rest"] = BigtableRestTransport def get_transport_class(