diff --git a/bigquery/README.md b/bigquery/README.md new file mode 100644 index 00000000000..5ed6c41ff66 --- /dev/null +++ b/bigquery/README.md @@ -0,0 +1,42 @@ +## bigquery-samples + +Sample code documenting usage of [Google BigQuery](https://cloud.google.com/bigquery/) using the [BigQuery Client Libraries](https://cloud.google.com/bigquery/client-libraries) + +[![Build Status](https://travis-ci.org/GoogleCloudPlatform/bigquery-samples-python.svg)](https://travis-ci.org/GoogleCloudPlatform/bigquery-samples-python) + +## Setup + +1. [Setup a project to use Google BigQuery](https://cloud.google.com/bigquery/sign-up) if you haven't already. + +2. [Generate a private key (JSON format)](https://cloud.google.com/storage/docs/authentication#generating-a-private-key) for your account. + +3. Make an environment variable: + ``` + export GOOGLE_APPLICATION_CREDENTIALS=/// + ``` + + +## Run + +From the `bigquery` directory run + +``` +pip install -r requirements.txt +``` + +Then to run a sample, simply use the interpreter + +``` +$ python +>>> from samples import +>>> .main() +``` + +## Contributing changes + +* See [CONTRIBUTING.md](CONTRIBUTING.md) + + +## Licensing + +* See [LICENSE](LICENSE) diff --git a/bigquery/samples/async_query.py b/bigquery/samples/async_query.py index 50deb3a4731..eba8d28c609 100644 --- a/bigquery/samples/async_query.py +++ b/bigquery/samples/async_query.py @@ -74,9 +74,8 @@ def main(): query_string = raw_input("Enter the Bigquery SQL Query: ") batch = raw_input("Run query as batch (y/n)?: ") in ( 'True', 'true', 'y', 'Y', 'yes', 'Yes') - - num_retries = raw_input( - "Enter number of times to retry in case of 500 error: ") + num_retries = int(raw_input( + "Enter number of times to retry in case of 500 error: ")) interval = raw_input( "Enter how often to poll the query for completion (seconds): ") diff --git a/bigquery/samples/utils.py b/bigquery/samples/utils.py index d35d0c94713..a9d70e93a5b 100644 --- a/bigquery/samples/utils.py +++ b/bigquery/samples/utils.py @@ -15,8 +15,12 @@ # [START get_service] def get_service(): - from discovery_doc import build_and_update - return build_and_update('bigquery', 'v2') + from googleapiclient.discovery import build + from oauth2client.client import GoogleCredentials + credentials = GoogleCredentials.get_application_default() + if credentials.create_scoped_required(): + credentials = credentials.create_scoped('https://www.googleapis.com/auth/bigquery') + return build('bigquery','v2', credentials=GoogleCredentials.get_application_default()) # [END get_service] diff --git a/datastore/ndb/README.md b/datastore/ndb/README.md index 262b47ba03a..56a14bb3632 100644 --- a/datastore/ndb/README.md +++ b/datastore/ndb/README.md @@ -1,5 +1,58 @@ -appengine-ndb-snippets -====================== +## NDB Overview Sample -Sample code snippets for NDB. +This is a sample app for Google App Engine that exercises the [NDB Python API](https://cloud.google.com/appengine/docs/python/ndb/). +See our other [Google Cloud Platform github +repos](https://github.com/GoogleCloudPlatform) for sample applications and +scaffolding for other python frameworks and use cases. + +## Run Locally +1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the [gcloud tool](https://cloud.google.com/sdk/gcloud/), and [gcloud app component](https://cloud.google.com/sdk/gcloud-app). +2. Setup the gcloud tool. + + ``` + gcloud components update app + gcloud auth login + gcloud config set project + ``` + You don't need a valid app-id to run locally, but will need a valid id to deploy below. + +1. Clone this repo. + + ``` + git clone https://github.com/GoogleCloudPlatform/python-docs-samples.git + cd python-docs-samples/datastore/ndb/ + ``` + +1. Run this project locally from the command line. + + ``` + gcloud preview app run ./ + ``` + +1. Visit the application at [http://localhost:8080](http://localhost:8080). + +## Deploying + +1. Use the [Cloud Developer Console](https://console.developer.google.com) to create a project/app id. (App id and project id are identical) +2. Configure gcloud with your app id. + + ``` + gcloud config set project + ``` +1. Use the [Admin Console](https://appengine.google.com) to view data, queues, and other App Engine specific administration tasks. +1. Use gcloud to deploy your app. + + ``` + gcloud preview app deploy ./ + ``` + +1. Congratulations! Your application is now live at your-app-id.appspot.com + +## Contributing changes + +* See [CONTRIBUTING.md](../../CONTRIBUTING.md) + +## Licensing + +* See [LICENSE](../../LICENSE) diff --git a/datastore/ndb/overview/README.md b/datastore/ndb/overview/README.md deleted file mode 100644 index 098498d50b8..00000000000 --- a/datastore/ndb/overview/README.md +++ /dev/null @@ -1,57 +0,0 @@ -## NDB Overview Sample - -This is a sample app for Google App Engine that exercises the [NDB Python API](https://cloud.google.com/appengine/docs/python/ndb/). - -See our other [Google Cloud Platform github -repos](https://github.com/GoogleCloudPlatform) for sample applications and -scaffolding for other python frameworks and use cases. - -## Run Locally -1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the [gcloud tool](https://cloud.google.com/sdk/gcloud/), and [gcloud app component](https://cloud.google.com/sdk/gcloud-app). -2. Setup the gcloud tool. - - ``` - gcloud components update app - gcloud auth login - gcloud config set project - ``` - You don't need a valid app-id to run locally, but will need a valid id to deploy below. - -1. Clone this repo. - - ``` - git clone https://github.com/GoogleCloudPlatform/datastore-pthon-samples.git - cd datastore-python-samples/ndb-overview - ``` -1. Run this project locally from the command line. - - ``` - gcloud preview app run ./ - ``` - -1. Visit the application at [http://localhost:8080](http://localhost:8080). - -## Deploying - -1. Use the [Cloud Developer Console](https://console.developer.google.com) to create a project/app id. (App id and project id are identical) -2. Configure gcloud with your app id. - - ``` - gcloud config set project - ``` -1. Use the [Admin Console](https://appengine.google.com) to view data, queues, and other App Engine specific administration tasks. -1. Use gcloud to deploy your app. - - ``` - gcloud preview app deploy ./ - ``` - -1. Congratulations! Your application is now live at your-app-id.appspot.com - -## Contributing changes - -* See [CONTRIBUTING.md](../../CONTRIBUTING.md) - -## Licensing - -* See [LICENSE](../../LICENSE) diff --git a/datastore/ndb/transactions/README.md b/datastore/ndb/transactions/README.md deleted file mode 100644 index 39c983ae0ac..00000000000 --- a/datastore/ndb/transactions/README.md +++ /dev/null @@ -1,61 +0,0 @@ -## NDB Transactions Sample - -This is a sample app for Google App Engine that exercises the [NDB Transactions Python API](https://cloud-dot-devsite.googleplex.com/appengine/docs/python/ndb/transactions) - -This app presents a list of notes. After you submit a note with a particular title, you may not change that note or submit a new note with the same title. There are multiple note pages available. - -See our other [Google Cloud Platform github -repos](https://github.com/GoogleCloudPlatform) for sample applications and -scaffolding for other python frameworks and use cases. - -## Run Locally -1. Install the [Google Cloud SDK](https://cloud.google.com/sdk/), including the [gcloud tool](https://cloud.google.com/sdk/gcloud/), and [gcloud app component](https://cloud.google.com/sdk/gcloud-app). -2. Setup the gcloud tool. - - ``` - gcloud components update app - gcloud auth login - gcloud config set project - ``` - You don't need a valid app-id to run locally, but will need a valid id to deploy below. - -1. Clone this repo. - - ``` - git clone https://github.com/GoogleCloudPlatform/datastore-samples.git - cd datastore-samples/python/ndb/transactions - ``` -1. Run this project locally from the command line. - - ``` - pip install -r requirements.txt -t lib/ - gcloud preview app run ./app.yaml - ``` - -1. Visit the application at [http://localhost:8080](http://localhost:8080). - -## Deploying - -1. Use the [Cloud Developer Console](https://console.developer.google.com) to create a project/app id. (App id and project id are identical) -2. Configure gcloud with your app id. - - ``` - gcloud config set project - ``` -1. Use the [Admin Console](https://appengine.google.com) to view data, queues, and other App Engine specific administration tasks. -1. Use gcloud to deploy your app. - - ``` - pip install -r requirements.txt -t lib/ - gcloud preview app deploy ./app.yaml - ``` - -1. Congratulations! Your application is now live at your-app-id.appspot.com - -## Contributing changes - -* See [CONTRIBUTING.md](../../../CONTRIBUTING.md) - -## Licensing - -* See [LICENSE](../../../LICENSE) diff --git a/bigquery/samples/discovery_doc.py b/discoverydoccaching/discovery_doc.py similarity index 100% rename from bigquery/samples/discovery_doc.py rename to discoverydoccaching/discovery_doc.py