Client¶
Parent client for calling the Google Cloud Bigtable API.
This is the base from which all interactions with the API occur.
In the hierarchy of API concepts
- a
Client
owns aCluster
- a
Cluster
owns aTable
- a
Table
owns aColumnFamily
- a
Table
owns aRow
(and all the cells in the row)
-
gcloud_bigtable.client.
ADMIN_SCOPE
= 'https://www.googleapis.com/auth/cloud-bigtable.admin'¶ Scope for interacting with the Cluster Admin and Table Admin APIs.
-
gcloud_bigtable.client.
CLUSTER_ADMIN_HOST
= 'bigtableclusteradmin.googleapis.com'¶ Cluster Admin API request host.
-
gcloud_bigtable.client.
CLUSTER_ADMIN_PORT
= 443¶ Cluster Admin API request port.
-
class
gcloud_bigtable.client.
Client
(credentials=None, project_id=None, read_only=False, admin=False, user_agent='gcloud-bigtable-python', timeout_seconds=10)[source]¶ Bases:
object
Client for interacting with Google Cloud Bigtable API.
Parameters: - credentials (
OAuth2Credentials
orNoneType
) – (Optional) The OAuth2 Credentials to use for this cluster. If not provided, defaulst to the Google Application Default Credentials. - project_id (
str
orunicode
) – (Optional) The ID of the project which owns the clusters, tables and data. If not provided, will attempt to determine from the environment. - read_only (bool) – (Optional) Boolean indicating if the data scope should be
for reading only (or for writing as well). Defaults to
False
. - admin (bool) – (Optional) Boolean indicating if the client will be used to
interact with the Cluster Admin or Table Admin APIs. This
requires the
ADMIN_SCOPE
. Defaults toFalse
. - user_agent (str) – (Optional) The user agent to be used with API request.
Defaults to
DEFAULT_USER_AGENT
. - timeout_seconds (int) – Number of seconds for request time-out. If not
passed, defaults to
DEFAULT_TIMEOUT_SECONDS
.
Raises: ValueError
if bothread_only
andadmin
areTrue
-
cluster
(zone, cluster_id, display_name=None, serve_nodes=3)[source]¶ Factory to create a cluster associated with this client.
Parameters: - zone (str) – The name of the zone where the cluster resides.
- cluster_id (str) – The ID of the cluster.
- display_name (str) – (Optional) The display name for the cluster in the Cloud Console UI. (Must be between 4 and 30 characters.) If this value is not set in the constructor, will fall back to the cluster ID.
- serve_nodes (int) – (Optional) The number of nodes in the cluster. Defaults to 3.
Return type: Returns: The cluster owned by this client.
-
cluster_stub
¶ Getter for the gRPC stub used for the Cluster Admin API.
Return type: grpc.early_adopter.implementations._Stub
Returns: A gRPC stub object. Raises: ValueError
if the current client is not an admin client or if it has not beenstart()
-ed.
-
credentials
¶ Getter for client’s credentials.
Return type: OAuth2Credentials
Returns: The credentials stored on the client.
-
data_stub
¶ Getter for the gRPC stub used for the Data API.
Return type: grpc.early_adopter.implementations._Stub
Returns: A gRPC stub object. Raises: ValueError
if the current client has not beenstart()
-ed.
-
classmethod
from_service_account_json
(json_credentials_path, project_id=None, read_only=False, admin=False)[source]¶ Factory to retrieve JSON credentials while creating client object.
Parameters: - json_credentials_path (str) – The path to a private key file (this file was given to you when you created the service account). This file must contain a JSON object with a private key and other credentials information (downloaded from the Google APIs console).
- project_id (str) – The ID of the project which owns the clusters,
tables and data. Will be passed to
Client
constructor. - read_only (bool) – Boolean indicating if the data scope should be
for reading only (or for writing as well). Will be
passed to
Client
constructor. - admin (bool) – Boolean indicating if the client will be used to
interact with the Cluster Admin or Table Admin APIs. Will
be passed to
Client
constructor.
Return type: Returns: The client created with the retrieved JSON credentials.
-
classmethod
from_service_account_p12
(client_email, private_key_path, project_id=None, read_only=False, admin=False)[source]¶ Factory to retrieve P12 credentials while creating client object.
Note
Unless you have an explicit reason to use a PKCS12 key for your service account, we recommend using a JSON key.
Parameters: - client_email (str) – The e-mail attached to the service account.
- private_key_path (str) – The path to a private key file (this file was given to you when you created the service account). This file must be in P12 format.
- project_id (str) – The ID of the project which owns the clusters,
tables and data. Will be passed to
Client
constructor. - read_only (bool) – Boolean indicating if the data scope should be
for reading only (or for writing as well). Will be
passed to
Client
constructor. - admin (bool) – Boolean indicating if the client will be used to
interact with the Cluster Admin or Table Admin APIs. Will
be passed to
Client
constructor.
Return type: Returns: The client created with the retrieved P12 credentials.
-
list_clusters
(timeout_seconds=None)[source]¶ Lists clusters owned by the project.
Parameters: timeout_seconds (int) – Number of seconds for request time-out. If not passed, defaults to value set on client. Return type: tuple Returns: A pair of results, the first is a list of Cluster
s returned and the second is a list of strings (the failed zones in the request).
-
list_zones
(timeout_seconds=None)[source]¶ Lists zones associated with project.
Parameters: timeout_seconds (int) – Number of seconds for request time-out. If not passed, defaults to value set on client. Return type: list Returns: The names (as str
) of the zonesRaises: ValueError
if one of the zones is not inOK
state.
-
operations_stub
¶ Getter for the gRPC stub used for the Operations API.
Return type: grpc.early_adopter.implementations._Stub
Returns: A gRPC stub object. Raises: ValueError
if the current client is not an admin client or if it has not beenstart()
-ed.
-
project_id
¶ Getter for client’s project ID.
Return type: str Returns: The project ID stored on the client.
-
project_name
¶ Project name to be used with Cluster Admin API.
Note
This property will not change if
project_id
does not, but the return value is not cached.The project name is of the form
"projects/{project_id}"
Return type: str Returns: The project name to be used with the Cloud Bigtable Admin API RPC service.
-
start
()[source]¶ Prepare the client to make requests.
Activates gRPC contexts for making requests to the Bigtable Service(s).
-
table_stub
¶ Getter for the gRPC stub used for the Table Admin API.
Return type: grpc.early_adopter.implementations._Stub
Returns: A gRPC stub object. Raises: ValueError
if the current client is not an admin client or if it has not beenstart()
-ed.
- credentials (
-
gcloud_bigtable.client.
DATA_API_HOST
= 'bigtable.googleapis.com'¶ Data API request host.
-
gcloud_bigtable.client.
DATA_API_PORT
= 443¶ Data API request port.
-
gcloud_bigtable.client.
DATA_SCOPE
= 'https://www.googleapis.com/auth/cloud-bigtable.data'¶ Scope for reading and writing table data.
-
gcloud_bigtable.client.
DEFAULT_TIMEOUT_SECONDS
= 10¶ The default timeout to use for API requests.
-
gcloud_bigtable.client.
DEFAULT_USER_AGENT
= 'gcloud-bigtable-python'¶ The default user agent for API requests.
-
gcloud_bigtable.client.
PROJECT_ENV_VAR
= 'GCLOUD_PROJECT'¶ Environment variable used to provide an implicit project ID.
-
gcloud_bigtable.client.
READ_ONLY_SCOPE
= 'https://www.googleapis.com/auth/cloud-bigtable.data.readonly'¶ Scope for reading table data.
-
gcloud_bigtable.client.
TABLE_ADMIN_HOST
= 'bigtabletableadmin.googleapis.com'¶ Table Admin API request host.
-
gcloud_bigtable.client.
TABLE_ADMIN_PORT
= 443¶ Table Admin API request port.