A quick class I put together to access Google BigQuery data via query through Python.
- Go to the Google APIs console to create a new project.
- Services > BigQuery > status ON
- API Access > "Create another client ID...". Choose "Service account" and click Create.
- Download your private keyfile.
- Note down your service account's email address and project number (Overview > Project number).
Some example usage with Google ngrams:
import easybigquery
API = GoogleAPIFromServiceAccount(projectNumber, serviceEmail, pathToKeyfile)
bq = GoogleBigQuery(API)
def rawNgramData(word):
query = "SELECT ngram, cell.volume_fraction FROM publicdata:samples.trigrams WHERE ngram CONTAINS '%s' GROUP BY ngram, cell.volume_fraction;" % word
return bq.query(query)
print rawNgramData("robot")