Skip to content

Commit 95e9fcd

Browse files
authored
Merge pull request googleapis#392 from GoogleCloudPlatform/tswast-bigtable-v2
Update Bigtable samples to v2.
2 parents 0dd3fcf + abce050 commit 95e9fcd

File tree

4 files changed

+83
-21
lines changed

4 files changed

+83
-21
lines changed

samples/hello/README.md

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,75 @@
11
# Cloud Bigtable Hello World
22

33
This is a simple application that demonstrates using the [Google Cloud Client
4-
Library][gcloud-python] to connect to and interact with Cloud Bigtable.
4+
Library][gcloud-python-bigtable] to connect to and interact with Cloud Bigtable.
55

6-
[gcloud-python]: https://github.com/GoogleCloudPlatform/gcloud-python
6+
<!-- auto-doc-link -->
7+
These samples are used on the following documentation page:
78

9+
> https://cloud.google.com/bigtable/docs/samples-python-hello
810
9-
## Provision a cluster
11+
<!-- end-auto-doc-link -->
1012

11-
Follow the instructions in the [user documentation](https://cloud.google.com/bigtable/docs/creating-cluster)
12-
to create a Google Cloud Platform project and Cloud Bigtable cluster if necessary.
13-
You'll need to reference your project ID, zone and cluster ID to run the application.
13+
[gcloud-python-bigtable]: https://googlecloudplatform.github.io/gcloud-python/stable/bigtable-usage.html
14+
[sample-docs]: https://cloud.google.com/bigtable/docs/samples-python-hello
1415

1516

16-
## Run the application
17+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
18+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
19+
**Table of Contents**
20+
21+
- [Downloading the sample](#downloading-the-sample)
22+
- [Costs](#costs)
23+
- [Provisioning an instance](#provisioning-an-instance)
24+
- [Running the application](#running-the-application)
25+
- [Cleaning up](#cleaning-up)
26+
27+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
28+
29+
30+
## Downloading the sample
31+
32+
Download the sample app and navigate into the app directory:
33+
34+
1. Clone the [Python samples
35+
repository](https://github.com/GoogleCloudPlatform/python-docs-samples), to
36+
your local machine:
37+
38+
git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git
39+
40+
Alternatively, you can [download the
41+
sample](https://github.com/GoogleCloudPlatform/python-docs-samples/archive/master.zip)
42+
as a zip file and extract it.
43+
44+
2. Change to the sample directory.
45+
46+
cd python-docs-samples/bigtable/hello
47+
48+
49+
## Costs
50+
51+
This sample uses billable components of Cloud Platform, including:
52+
53+
+ Google Cloud Bigtable
54+
55+
Use the [Pricing Calculator][bigtable-pricing] to generate a cost estimate
56+
based on your projected usage. New Cloud Platform users might be eligible for
57+
a [free trial][free-trial].
58+
59+
[bigtable-pricing]: https://cloud.google.com/products/calculator/#id=1eb47664-13a2-4be1-9d16-6722902a7572
60+
[free-trial]: https://cloud.google.com/free-trial
61+
62+
63+
## Provisioning an instance
64+
65+
Follow the instructions in the [user
66+
documentation](https://cloud.google.com/bigtable/docs/creating-instance) to
67+
create a Google Cloud Platform project and Cloud Bigtable instance if necessary.
68+
You'll need to reference your project id and instance id to run the
69+
application.
70+
71+
72+
## Running the application
1773

1874
First, set your [Google Application Default Credentials](https://developers.google.com/identity/protocols/application-default-credentials)
1975

@@ -23,20 +79,29 @@ Install the dependencies with pip.
2379
$ pip install -r requirements.txt
2480
```
2581

26-
Run the application. Replace the command-line parameters with values for your cluster.
82+
Run the application. Replace the command-line parameters with values for your instance.
2783

2884
```
29-
$ python main.py my-project my-cluster us-central1-c
85+
$ python main.py my-project my-instance
3086
```
3187

3288
You will see output resembling the following:
3389

3490
```
35-
Create table Hello-Bigtable-1234
91+
Create table Hello-Bigtable
3692
Write some greetings to the table
3793
Scan for all greetings:
3894
greeting0: Hello World!
3995
greeting1: Hello Cloud Bigtable!
4096
greeting2: Hello HappyBase!
41-
Delete table Hello-Bigtable-1234
97+
Delete table Hello-Bigtable
4298
```
99+
100+
101+
## Cleaning up
102+
103+
To avoid incurring extra charges to your Google Cloud Platform account, remove
104+
the resources created for this sample.
105+
106+
- [Delete the Cloud Bigtable
107+
instance](https://cloud.google.com/bigtable/docs/deleting-instance).

samples/hello/main.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
from gcloud import bigtable
3030

3131

32-
def main(project_id, cluster_id, zone, table_id):
32+
def main(project_id, instance_id, table_id):
3333
# [START connecting_to_bigtable]
3434
# The client must be created with admin=True because it will create a
3535
# table.
3636
with bigtable.Client(project=project_id, admin=True) as client:
37-
cluster = client.cluster(zone, cluster_id)
37+
instance = client.instance(instance_id)
3838
# [END connecting_to_bigtable]
3939

4040
# [START creating_a_table]
4141
print('Creating the {} table.'.format(table_id))
42-
table = cluster.table(table_id)
42+
table = instance.table(table_id)
4343
table.create()
4444
column_family_id = 'cf1'
4545
cf1 = table.column_family(column_family_id)
@@ -107,13 +107,11 @@ def main(project_id, cluster_id, zone, table_id):
107107
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
108108
parser.add_argument('project_id', help='Your Cloud Platform project ID.')
109109
parser.add_argument(
110-
'cluster', help='ID of the Cloud Bigtable cluster to connect to.')
111-
parser.add_argument(
112-
'zone', help='Zone that contains the Cloud Bigtable cluster.')
110+
'instance_id', help='ID of the Cloud Bigtable instance to connect to.')
113111
parser.add_argument(
114112
'--table',
115113
help='Table to create and destroy.',
116114
default='Hello-Bigtable')
117115

118116
args = parser.parse_args()
119-
main(args.project_id, args.cluster, args.zone, args.table)
117+
main(args.project_id, args.instance_id, args.table)

samples/hello/main_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ def test_main(cloud_config, capsys):
3333
random.randrange(TABLE_NAME_RANGE))
3434
main(
3535
cloud_config.project,
36-
cloud_config.bigtable_cluster,
37-
cloud_config.bigtable_zone,
36+
cloud_config.bigtable_instance,
3837
table_name)
3938

4039
out, _ = capsys.readouterr()

samples/hello/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
gcloud[grpc]==0.16.0
1+
gcloud[grpc]==0.17.0

0 commit comments

Comments
 (0)