|
| 1 | +.. This file is automatically generated. Do not edit this file directly. |
| 2 | +
|
| 3 | +Google Cloud Bigtable Python Samples |
| 4 | +=============================================================================== |
| 5 | + |
| 6 | +This directory contains samples for Google Cloud Bigtable. `Google Cloud Bigtable`_ is Google's NoSQL Big Data database service. It's the same database that powers many core Google services, including Search, Analytics, Maps, and Gmail. |
| 7 | + |
| 8 | + |
| 9 | +This sample demonstrates using the `Google Cloud Client Library HappyBase |
| 10 | +package`_, an implementation of the `HappyBase API`_ to connect to and |
| 11 | +interact with Cloud Bigtable. |
| 12 | + |
| 13 | +.. _Google Cloud Client Library HappyBase package: |
| 14 | + https://github.com/GoogleCloudPlatform/google-cloud-python-happybase |
| 15 | +.. _HappyBase API: http://happybase.readthedocs.io/en/stable/ |
| 16 | + |
| 17 | + |
| 18 | +.. _Google Cloud Bigtable: https://cloud.google.com/bigtable/docs |
| 19 | + |
| 20 | +Setup |
| 21 | +------------------------------------------------------------------------------- |
| 22 | + |
| 23 | + |
| 24 | +Authentication |
| 25 | +++++++++++++++ |
| 26 | + |
| 27 | +Authentication is typically done through `Application Default Credentials`_, |
| 28 | +which means you do not have to change the code to authenticate as long as |
| 29 | +your environment has credentials. You have a few options for setting up |
| 30 | +authentication: |
| 31 | + |
| 32 | +#. When running locally, use the `Google Cloud SDK`_ |
| 33 | + |
| 34 | + .. code-block:: bash |
| 35 | +
|
| 36 | + gcloud beta auth application-default login |
| 37 | +
|
| 38 | +
|
| 39 | +#. When running on App Engine or Compute Engine, credentials are already |
| 40 | + set-up. However, you may need to configure your Compute Engine instance |
| 41 | + with `additional scopes`_. |
| 42 | + |
| 43 | +#. You can create a `Service Account key file`_. This file can be used to |
| 44 | + authenticate to Google Cloud Platform services from any environment. To use |
| 45 | + the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to |
| 46 | + the path to the key file, for example: |
| 47 | + |
| 48 | + .. code-block:: bash |
| 49 | +
|
| 50 | + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json |
| 51 | +
|
| 52 | +.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow |
| 53 | +.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using |
| 54 | +.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount |
| 55 | + |
| 56 | +Install Dependencies |
| 57 | +++++++++++++++++++++ |
| 58 | + |
| 59 | +#. Install `pip`_ and `virtualenv`_ if you do not already have them. |
| 60 | + |
| 61 | +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. |
| 62 | + |
| 63 | + .. code-block:: bash |
| 64 | +
|
| 65 | + $ virtualenv env |
| 66 | + $ source env/bin/activate |
| 67 | +
|
| 68 | +#. Install the dependencies needed to run the samples. |
| 69 | + |
| 70 | + .. code-block:: bash |
| 71 | +
|
| 72 | + $ pip install -r requirements.txt |
| 73 | +
|
| 74 | +.. _pip: https://pip.pypa.io/ |
| 75 | +.. _virtualenv: https://virtualenv.pypa.io/ |
| 76 | + |
| 77 | +Samples |
| 78 | +------------------------------------------------------------------------------- |
| 79 | + |
| 80 | +Basic example |
| 81 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +To run this sample: |
| 86 | + |
| 87 | +.. code-block:: bash |
| 88 | +
|
| 89 | + $ python main.py |
| 90 | +
|
| 91 | + usage: main.py [-h] [--table TABLE] project_id instance_id |
| 92 | + |
| 93 | + Demonstrates how to connect to Cloud Bigtable and run some basic operations. |
| 94 | + Prerequisites: - Create a Cloud Bigtable cluster. |
| 95 | + https://cloud.google.com/bigtable/docs/creating-cluster - Set your Google |
| 96 | + Application Default Credentials. |
| 97 | + https://developers.google.com/identity/protocols/application-default- |
| 98 | + credentials |
| 99 | + |
| 100 | + positional arguments: |
| 101 | + project_id Your Cloud Platform project ID. |
| 102 | + instance_id ID of the Cloud Bigtable instance to connect to. |
| 103 | + |
| 104 | + optional arguments: |
| 105 | + -h, --help show this help message and exit |
| 106 | + --table TABLE Table to create and destroy. (default: Hello-Bigtable) |
| 107 | +
|
| 108 | +
|
| 109 | +
|
| 110 | +
|
| 111 | +The client library |
| 112 | +------------------------------------------------------------------------------- |
| 113 | + |
| 114 | +This sample uses the `Google Cloud Client Library for Python`_. |
| 115 | +You can read the documentation for more details on API usage and use GitHub |
| 116 | +to `browse the source`_ and `report issues`_. |
| 117 | + |
| 118 | +.. Google Cloud Client Library for Python: |
| 119 | + https://googlecloudplatform.github.io/google-cloud-python/ |
| 120 | +.. browse the source: |
| 121 | + https://github.com/GoogleCloudPlatform/google-cloud-python |
| 122 | +.. report issues: |
| 123 | + https://github.com/GoogleCloudPlatform/google-cloud-python/issues |
| 124 | +
|
| 125 | +
|
| 126 | +.. _Google Cloud SDK: https://cloud.google.com/sdk/ |
0 commit comments