HappyBase Connection#
Google Cloud Bigtable HappyBase connection module.
-
class
google.cloud.happybase.connection.
Connection
(timeout=None, autoconnect=True, table_prefix=None, table_prefix_separator='_', instance=None, **kwargs)[source]# Bases:
object
Connection to Cloud Bigtable backend.
Note
If you pass a
instance
, it will beInstance.copy()
-ed before being stored on the new connection. This also copies theClient
that created theInstance
instance and theCredentials
stored on the client.The arguments
host
,port
,compat
,transport
andprotocol
are allowed (as keyword arguments) for compatibility with HappyBase. However, they will not be used in any way, and will cause a warning if passed.Parameters: - timeout (int) – (Optional) The socket timeout in milliseconds.
- autoconnect (bool) – (Optional) Whether the connection should be
open()
-ed during construction. - table_prefix (str) – (Optional) Prefix used to construct table names.
- table_prefix_separator (str) – (Optional) Separator used with
table_prefix
. Defaults to_
. - instance (
Instance
) – (Optional) A Cloud Bigtable instance. The instance also owns a client for making gRPC requests to the Cloud Bigtable API. If not passed in, defaults to creating client withadmin=True
and using thetimeout
here for thetimeout_seconds
argument to theClient
constructor. The credentials for the client will be the implicit ones loaded from the environment. Then that client is used to retrieve all the instances owned by the client’s project. - kwargs (dict) – Remaining keyword arguments. Provided for HappyBase compatibility.
-
close
()[source]# Close the underlying transport to Cloud Bigtable.
This method does nothing and is provided for compatibility.
-
static
compact_table
(name, major=False)[source]# Compact the specified table.
Warning
Cloud Bigtable supports table compactions, it just doesn’t expose an API for that feature, so this method does nothing. It is provided simply for compatibility.
Parameters:
-
create_table
(name, families)[source]# Create a table.
Warning
The only column family options from HappyBase that are able to be used with Cloud Bigtable are
max_versions
andtime_to_live
.Values in
families
represent column family options. In HappyBase, these are dictionaries, corresponding to theColumnDescriptor
structure in the Thrift API. The accepted keys are:max_versions
(int
)compression
(str
)in_memory
(bool
)bloom_filter_type
(str
)bloom_filter_vector_size
(int
)bloom_filter_nb_hashes
(int
)block_cache_enabled
(bool
)time_to_live
(int
)
Parameters: Raises: - TypeError – If
families
is not a dictionary. - ValueError – If
families
has no entries. - AlreadyExists – If creation fails due to an already existing table.
- NetworkError – If creation fails for a reason other than table exists.
-
delete_table
(name, disable=False)[source]# Delete the specified table.
Parameters: - name (str) – The name of the table to be deleted. If
table_prefix
is set, a prefix will be added to thename
. - disable (bool) – Whether to first disable the table if needed. This is provided for compatibility with HappyBase, but is not relevant for Cloud Bigtable since it has no concept of enabled / disabled tables.
- name (str) – The name of the table to be deleted. If
-
static
disable_table
(name)[source]# Disable the specified table.
Warning
Cloud Bigtable has no concept of enabled / disabled tables so this method does nothing. It is provided simply for compatibility.
Parameters: name (str) – The name of the table to be disabled.
-
static
enable_table
(name)[source]# Enable the specified table.
Warning
Cloud Bigtable has no concept of enabled / disabled tables so this method does nothing. It is provided simply for compatibility.
Parameters: name (str) – The name of the table to be enabled.
-
static
is_table_enabled
(name)[source]# Return whether the specified table is enabled.
Warning
Cloud Bigtable has no concept of enabled / disabled tables so this method always returns
True
. It is provided simply for compatibility.Parameters: name (str) – The name of the table to check enabled / disabled status. Return type: bool Returns: The value True
always.
-
open
()[source]# Open the underlying transport to Cloud Bigtable.
This method does nothing and is provided for compatibility.
-
table
(name, use_prefix=True)[source]# Table factory.
Parameters: Return type: Returns: Table instance owned by this connection.
-
tables
()[source]# Return a list of table names available to this connection.
Note
This lists every table in the instance owned by this connection, not every table that a given user may have access to.
Note
If
table_prefix
is set on this connection, only returns the table names which match that prefix.Return type: list Returns: List of string table names.