Skip to content

Commit 470e41b

Browse files
committed
Add some simple "quickstart" samples.
1 parent 85d4b1c commit 470e41b

File tree

7 files changed

+208
-0
lines changed

7 files changed

+208
-0
lines changed

bigquery/cloud-client/quickstart.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
# [START bigquery_quickstart]
18+
# Imports the Google Cloud client library
19+
from google.cloud import bigquery
20+
21+
# Instantiates a client
22+
bigquery_client = bigquery.Client()
23+
24+
# The name for the new dataset
25+
dataset_name = 'my_new_dataset'
26+
27+
# Prepares the new dataset
28+
dataset = bigquery_client.dataset(dataset_name)
29+
30+
# Creates the new dataset
31+
dataset.create()
32+
33+
print('Dataset {} created'.format(dataset.name))
34+
# [END bigquery_quickstart]

datastore/api/quickstart.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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+
# [START datastore_quickstart]
18+
# Imports the Google Cloud client library
19+
from google.cloud import datastore
20+
21+
# Instantiates a client
22+
datastore_client = datastore.Client()
23+
24+
# The kind of the entity to retrieve
25+
kind = 'Task'
26+
# The id of the entity to retrieve
27+
id = 1234567890
28+
# The Datastore key for the entity
29+
task_key = datastore_client.key(kind, id)
30+
31+
# Retrieves the entity
32+
entity = datastore_client.get(task_key)
33+
34+
print('Got entity: {}'.format(entity.key.id))
35+
# [END datastore_quickstart]

logging/cloud-client/quickstart.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
# [START logging_quickstart]
18+
# Imports the Google Cloud client library
19+
from google.cloud import logging
20+
21+
# Instantiates a client
22+
logging_client = logging.Client()
23+
24+
# The name of the log to write to
25+
log_name = 'my-log'
26+
# Selects the log to write to
27+
logger = logging_client.logger(log_name)
28+
29+
# The data to log
30+
text = 'Hello, world!'
31+
32+
# Writes the log entry
33+
logger.log_text(text)
34+
35+
print('Logged: {}'.format(text))
36+
# [END logging_quickstart]

pubsub/cloud-client/quickstart.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
# [START pubsub_quickstart]
18+
# Imports the Google Cloud client library
19+
from google.cloud import pubsub
20+
21+
# Instantiates a client
22+
pubsub_client = pubsub.Client()
23+
24+
# The name for the new topic
25+
topic_name = 'my-new-topic'
26+
27+
# Prepares the new topic
28+
topic = pubsub_client.topic(topic_name)
29+
30+
# Creates the new topic
31+
topic.create()
32+
33+
print('Topic {} created'.format(topic.name))
34+
# [END pubsub_quickstart]

storage/cloud-client/quickstart.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
# [START storage_quickstart]
18+
# Imports the Google Cloud client library
19+
from google.cloud import storage
20+
21+
# Instantiates a client
22+
storage_client = storage.Client()
23+
24+
# The name for the new bucket
25+
bucket_name = 'my-new-bucket'
26+
27+
# Creates the new bucket
28+
bucket = storage_client.create_bucket(bucket_name)
29+
30+
print('Bucket {} created'.format(bucket.name))
31+
# [END storage_quickstart]

translate/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+
# [START translate_quickstart]
18+
# Imports the Google Cloud client library
19+
from google.cloud import translate
20+
21+
# Your Translate API key
22+
api_key = 'YOUR_API_KEY'
23+
24+
# Instantiates a client
25+
translate_client = translate.Client(api_key)
26+
27+
# The text to translate
28+
text = 'Hello, world!'
29+
# The target language
30+
target = 'ru'
31+
32+
# Translates some text into Russian
33+
translation = translate_client.translate(text, target_language=target)
34+
35+
print('Text: {}'.format(text))
36+
print('Translation: {}'.format(translation['translatedText'].encode('utf-8')))
37+
# [END translate_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

0 commit comments

Comments
 (0)