Report an Issue

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: object

Connection to Cloud Bigtable backend.

Note

If you pass a instance, it will be Instance.copy()-ed before being stored on the new connection. This also copies the Client that created the Instance instance and the Credentials stored on the client.

The arguments host, port, compat, transport and protocol 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 with admin=True and using the timeout here for the timeout_seconds argument to the Client 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 closes the underlying HTTP/2 gRPC connection using a Client bound to the Instance owned 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:NotImplementedError always
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 and time_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 families represent column family options. In HappyBase, these are dictionaries, corresponding to the ColumnDescriptor 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:
  • name (str) – The name of the table to be created.
  • families (dict) –

    Dictionary with column family names as keys and column family options as the values. The options can be among

Raises:

TypeError if families is not a dictionary, ValueError if families has 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_prefix is set, a prefix will be added to the name.
  • 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.
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:NotImplementedError always
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:NotImplementedError always
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:NotImplementedError always
open()[source]#

Open the underlying transport to Cloud Bigtable.

This method opens the underlying HTTP/2 gRPC connection using a Client bound to the Instance owned by this connection.

table(name, use_prefix=True)[source]#

Table factory.

Parameters:
  • name (str) – The name of the table to be created.
  • use_prefix (bool) – Whether to use the table prefix (if any).
Return type:

Table

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.