HappyBase Connection#
Warning
gRPC is required for using the Cloud Bigtable API. As of May 2016,
grpcio is only supported in Python 2.7, so importing
gcloud.bigtable in other versions of Python will fail.
Google Cloud Bigtable HappyBase connection module.
-
class
gcloud.bigtable.happybase.connection.Connection(timeout=None, autoconnect=True, table_prefix=None, table_prefix_separator='_', instance=None, **kwargs)[source]# Bases:
objectConnection 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 theClientthat created theInstanceinstance and theCredentialsstored on the client.The arguments
host,port,compat,transportandprotocolare 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=Trueand using thetimeouthere for thetimeout_secondsargument to theClientconstructor. 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 closes the underlying HTTP/2 gRPC connection using a
Clientbound to theInstanceowned by this connection.
-
compact_table(name, major=False)[source]# Compact the specified table.
Warning
Cloud Bigtable does not support compacting a table, so this method does not work. It is provided simply for compatibility.
Raises: NotImplementedErroralways
-
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_versionsandtime_to_live.Note
This method is not atomic. The Cloud Bigtable API separates the creation of a table from the creation of column families. Thus this method needs to send 1 request for the table creation and 1 request for each column family. If any of these fails, the method will fail, but the progress made towards completion cannot be rolled back.
Values in
familiesrepresent column family options. In HappyBase, these are dictionaries, corresponding to theColumnDescriptorstructure 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: TypeErroriffamiliesis not a dictionary,ValueErroriffamilieshas no entries
-
delete_table(name, disable=False)[source]# Delete the specified table.
Parameters: - name (str) – The name of the table to be deleted. If
table_prefixis 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
-
disable_table(name)[source]# Disable the specified table.
Warning
Cloud Bigtable has no concept of enabled / disabled tables so this method does not work. It is provided simply for compatibility.
Raises: NotImplementedErroralways
-
enable_table(name)[source]# Enable the specified table.
Warning
Cloud Bigtable has no concept of enabled / disabled tables so this method does not work. It is provided simply for compatibility.
Raises: NotImplementedErroralways
-
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 does not work. It is provided simply for compatibility.
Raises: NotImplementedErroralways
-
open()[source]# Open the underlying transport to Cloud Bigtable.
This method opens the underlying HTTP/2 gRPC connection using a
Clientbound to theInstanceowned by this connection.
-
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_prefixis set on this connection, only returns the table names which match that prefix.Return type: list Returns: List of string table names.