diff --git a/samples/hello/README.md b/samples/hello/README.md deleted file mode 100644 index 5057e2571..000000000 --- a/samples/hello/README.md +++ /dev/null @@ -1,107 +0,0 @@ -# Cloud Bigtable Hello World - -This is a simple application that demonstrates using the [Google Cloud Client -Library][gcloud-python-bigtable] to connect to and interact with Cloud Bigtable. - - -These samples are used on the following documentation page: - -> https://cloud.google.com/bigtable/docs/samples-python-hello - - - -[gcloud-python-bigtable]: https://googlecloudplatform.github.io/gcloud-python/stable/bigtable-usage.html -[sample-docs]: https://cloud.google.com/bigtable/docs/samples-python-hello - - - - -**Table of Contents** - -- [Downloading the sample](#downloading-the-sample) -- [Costs](#costs) -- [Provisioning an instance](#provisioning-an-instance) -- [Running the application](#running-the-application) -- [Cleaning up](#cleaning-up) - - - - -## Downloading the sample - -Download the sample app and navigate into the app directory: - -1. Clone the [Python samples - repository](https://github.com/GoogleCloudPlatform/python-docs-samples), to - your local machine: - - git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git - - Alternatively, you can [download the - sample](https://github.com/GoogleCloudPlatform/python-docs-samples/archive/master.zip) - as a zip file and extract it. - -2. Change to the sample directory. - - cd python-docs-samples/bigtable/hello - - -## Costs - -This sample uses billable components of Cloud Platform, including: - -+ Google Cloud Bigtable - -Use the [Pricing Calculator][bigtable-pricing] to generate a cost estimate -based on your projected usage. New Cloud Platform users might be eligible for -a [free trial][free-trial]. - -[bigtable-pricing]: https://cloud.google.com/products/calculator/#id=1eb47664-13a2-4be1-9d16-6722902a7572 -[free-trial]: https://cloud.google.com/free-trial - - -## Provisioning an instance - -Follow the instructions in the [user -documentation](https://cloud.google.com/bigtable/docs/creating-instance) to -create a Google Cloud Platform project and Cloud Bigtable instance if necessary. -You'll need to reference your project id and instance id to run the -application. - - -## Running the application - -First, set your [Google Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials) - -Install the dependencies with pip. - -``` -$ pip install -r requirements.txt -``` - -Run the application. Replace the command-line parameters with values for your instance. - -``` -$ python main.py my-project my-instance -``` - -You will see output resembling the following: - -``` -Create table Hello-Bigtable -Write some greetings to the table -Scan for all greetings: - greeting0: Hello World! - greeting1: Hello Cloud Bigtable! - greeting2: Hello HappyBase! -Delete table Hello-Bigtable -``` - - -## Cleaning up - -To avoid incurring extra charges to your Google Cloud Platform account, remove -the resources created for this sample. - -- [Delete the Cloud Bigtable - instance](https://cloud.google.com/bigtable/docs/deleting-instance). diff --git a/samples/hello/README.rst b/samples/hello/README.rst new file mode 100644 index 000000000..a1a327f45 --- /dev/null +++ b/samples/hello/README.rst @@ -0,0 +1,119 @@ +.. This file is automatically generated. Do not edit this file directly. + +Google Cloud Bigtable Python Samples +=============================================================================== + +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. + + + + +.. _Google Cloud Bigtable: https://cloud.google.com/bigtable/docs + +Setup +------------------------------------------------------------------------------- + + +Authentication +++++++++++++++ + +Authentication is typically done through `Application Default Credentials`_, +which means you do not have to change the code to authenticate as long as +your environment has credentials. You have a few options for setting up +authentication: + +#. When running locally, use the `Google Cloud SDK`_ + + .. code-block:: bash + + gcloud beta auth application-default login + + +#. When running on App Engine or Compute Engine, credentials are already + set-up. However, you may need to configure your Compute Engine instance + with `additional scopes`_. + +#. You can create a `Service Account key file`_. This file can be used to + authenticate to Google Cloud Platform services from any environment. To use + the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to + the path to the key file, for example: + + .. code-block:: bash + + export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json + +.. _Application Default Credentials: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow +.. _additional scopes: https://cloud.google.com/compute/docs/authentication#using +.. _Service Account key file: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount + +Install Dependencies +++++++++++++++++++++ + +#. Install `pip`_ and `virtualenv`_ if you do not already have them. + +#. Create a virtualenv. Samples are compatible with Python 2.7 and 3.4+. + + .. code-block:: bash + + $ virtualenv env + $ source env/bin/activate + +#. Install the dependencies needed to run the samples. + + .. code-block:: bash + + $ pip install -r requirements.txt + +.. _pip: https://pip.pypa.io/ +.. _virtualenv: https://virtualenv.pypa.io/ + +Samples +------------------------------------------------------------------------------- + +Basic example ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + + + +To run this sample: + +.. code-block:: bash + + $ python main.py + + usage: main.py [-h] [--table TABLE] project_id instance_id + + Demonstrates how to connect to Cloud Bigtable and run some basic operations. + Prerequisites: - Create a Cloud Bigtable cluster. + https://cloud.google.com/bigtable/docs/creating-cluster - Set your Google + Application Default Credentials. + https://developers.google.com/identity/protocols/application-default- + credentials + + positional arguments: + project_id Your Cloud Platform project ID. + instance_id ID of the Cloud Bigtable instance to connect to. + + optional arguments: + -h, --help show this help message and exit + --table TABLE Table to create and destroy. (default: Hello-Bigtable) + + + + +The client library +------------------------------------------------------------------------------- + +This sample uses the `Google Cloud Client Library for Python`_. +You can read the documentation for more details on API usage and use GitHub +to `browse the source`_ and `report issues`_. + +.. Google Cloud Client Library for Python: + https://googlecloudplatform.github.io/google-cloud-python/ +.. browse the source: + https://github.com/GoogleCloudPlatform/google-cloud-python +.. report issues: + https://github.com/GoogleCloudPlatform/google-cloud-python/issues + + +.. _Google Cloud SDK: https://cloud.google.com/sdk/ \ No newline at end of file diff --git a/samples/hello/README.rst.in b/samples/hello/README.rst.in new file mode 100644 index 000000000..7551bc0de --- /dev/null +++ b/samples/hello/README.rst.in @@ -0,0 +1,21 @@ +# This file is used to generate README.rst + +product: + name: Google Cloud Bigtable + short_name: Cloud Bigtable + url: https://cloud.google.com/bigtable/docs + description: > + `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. + +setup: +- auth +- install_deps + +samples: +- name: Basic example + file: main.py + show_help: true + +cloud_client_library: true