Skip to content

Commit 960e8ef

Browse files
jmdobryJon Wayne Parrott
authored and
Jon Wayne Parrott
committed
Add new "quickstart" samples (#547)
1 parent 272e37e commit 960e8ef

File tree

12 files changed

+331
-0
lines changed

12 files changed

+331
-0
lines changed

bigquery/cloud-client/quickstart.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START bigquery_quickstart]
20+
# Imports the Google Cloud client library
21+
from google.cloud import bigquery
22+
23+
# Instantiates a client
24+
bigquery_client = bigquery.Client()
25+
26+
# The name for the new dataset
27+
dataset_name = 'my_new_dataset'
28+
29+
# Prepares the new dataset
30+
dataset = bigquery_client.dataset(dataset_name)
31+
32+
# Creates the new dataset
33+
dataset.create()
34+
35+
print('Dataset {} created.'.format(dataset.name))
36+
# [END bigquery_quickstart]
37+
38+
39+
if __name__ == '__main__':
40+
run_quickstart()

datastore/api/quickstart.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START datastore_quickstart]
20+
# Imports the Google Cloud client library
21+
from google.cloud import datastore
22+
23+
# Instantiates a client
24+
datastore_client = datastore.Client()
25+
26+
# The kind of the entity to retrieve
27+
kind = 'Person'
28+
# The name/ID of the entity to retrieve
29+
name = 'Bob'
30+
# The Datastore key for the entity
31+
task_key = datastore_client.key(kind, name)
32+
33+
# Retrieves the entity
34+
entity = datastore_client.get(task_key)
35+
36+
print('Fetched entity: {}'.format(entity.key.name))
37+
# [END datastore_quickstart]
38+
39+
40+
if __name__ == '__main__':
41+
run_quickstart()

language/cloud-client/quickstart.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START language_quickstart]
20+
# Imports the Google Cloud client library
21+
from google.cloud import language
22+
23+
# Instantiates a client
24+
language_client = language.Client()
25+
26+
# The text to analyze
27+
text = 'Hello, world!'
28+
document = language_client.document_from_text(text)
29+
30+
# Detects the sentiment of the text
31+
sentiment = document.analyze_sentiment()
32+
33+
print('Text: {}'.format(text))
34+
print('Sentiment: {}, {}'.format(sentiment.polarity, sentiment.magnitude))
35+
# [END language_quickstart]
36+
37+
38+
if __name__ == '__main__':
39+
run_quickstart()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-language==0.20.0

logging/cloud-client/quickstart.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START logging_quickstart]
20+
# Imports the Google Cloud client library
21+
from google.cloud import logging
22+
23+
# Instantiates a client
24+
logging_client = logging.Client()
25+
26+
# The name of the log to write to
27+
log_name = 'my-log'
28+
# Selects the log to write to
29+
logger = logging_client.logger(log_name)
30+
31+
# The data to log
32+
text = 'Hello, world!'
33+
34+
# Writes the log entry
35+
logger.log_text(text)
36+
37+
print('Logged: {}'.format(text))
38+
# [END logging_quickstart]
39+
40+
41+
if __name__ == '__main__':
42+
run_quickstart()

pubsub/cloud-client/quickstart.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START pubsub_quickstart]
20+
# Imports the Google Cloud client library
21+
from google.cloud import pubsub
22+
23+
# Instantiates a client
24+
pubsub_client = pubsub.Client()
25+
26+
# The name for the new topic
27+
topic_name = 'my-new-topic'
28+
29+
# Prepares the new topic
30+
topic = pubsub_client.topic(topic_name)
31+
32+
# Creates the new topic
33+
topic.create()
34+
35+
print('Topic {} created.'.format(topic.name))
36+
# [END pubsub_quickstart]
37+
38+
39+
if __name__ == '__main__':
40+
run_quickstart()

storage/cloud-client/quickstart.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START storage_quickstart]
20+
# Imports the Google Cloud client library
21+
from google.cloud import storage
22+
23+
# Instantiates a client
24+
storage_client = storage.Client()
25+
26+
# The name for the new bucket
27+
bucket_name = 'my-new-bucket'
28+
29+
# Creates the new bucket
30+
bucket = storage_client.create_bucket(bucket_name)
31+
32+
print('Bucket {} created.'.format(bucket.name))
33+
# [END storage_quickstart]
34+
35+
36+
if __name__ == '__main__':
37+
run_quickstart()

translate/cloud-client/quickstart.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START translate_quickstart]
20+
# Imports the Google Cloud client library
21+
from google.cloud import translate
22+
23+
# Your Translate API key
24+
api_key = 'YOUR_API_KEY'
25+
26+
# Instantiates a client
27+
translate_client = translate.Client(api_key)
28+
29+
# The text to translate
30+
text = 'Hello, world!'
31+
# The target language
32+
target = 'ru'
33+
34+
# Translates some text into Russian
35+
translation = translate_client.translate(text, target_language=target)
36+
37+
print('Text: {}'.format(text))
38+
print('Translation: {}'.format(
39+
translation['translatedText'].encode('utf-8')))
40+
# [END translate_quickstart]
41+
42+
43+
if __name__ == '__main__':
44+
run_quickstart()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-translate==0.20.0

vision/cloud-client/quickstart.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright 2016 Google Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
18+
def run_quickstart():
19+
# [START vision_quickstart]
20+
import io
21+
22+
# Imports the Google Cloud client library
23+
from google.cloud import vision
24+
25+
# Instantiates a client
26+
vision_client = vision.Client()
27+
28+
# The name of the image file to annotate
29+
fileName = './resources/wakeupcat.jpg'
30+
31+
# Loads the image into memory
32+
with io.open(fileName, 'rb') as image_file:
33+
image = vision_client.image(content=image_file.read())
34+
35+
# Performs label detection on the image file
36+
labels = image.detect_labels()
37+
38+
print('Labels:')
39+
for label in labels:
40+
print(label.description)
41+
# [END vision_quickstart]
42+
43+
44+
if __name__ == '__main__':
45+
run_quickstart()

vision/cloud-client/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
google-cloud-vision==0.20.0
63.4 KB
Loading

0 commit comments

Comments
 (0)