Google BigQuery API client library
Project description
Python idiomatic client for Google BigQuery
Quick Start
$ pip install --upgrade google-cloud-bigquery
For more information on setting up your Python development environment, such as installing pip and virtualenv on your system, please refer to Python Development Environment Setup Guide for Google Cloud Platform.
Authentication
With google-cloud-python we try to make authentication as painless as possible. Check out the Authentication section in our documentation to learn more. You may also find the authentication document shared by all the google-cloud-* libraries to be helpful.
Using the API
Querying massive datasets can be time consuming and expensive without the right hardware and infrastructure. Google BigQuery (BigQuery API docs) solves this problem by enabling super-fast, SQL queries against append-mostly tables, using the processing power of Google’s infrastructure.
Create a dataset
from google.cloud import bigquery
from google.cloud.bigquery import Dataset
client = bigquery.Client()
dataset_ref = client.dataset('dataset_name')
dataset = Dataset(dataset_ref)
dataset.description = 'my dataset'
dataset = client.create_dataset(dataset) # API request
Load data from CSV
import csv
from google.cloud import bigquery
from google.cloud.bigquery import LoadJobConfig
from google.cloud.bigquery import SchemaField
client = bigquery.Client()
SCHEMA = [
SchemaField('full_name', 'STRING', mode='required'),
SchemaField('age', 'INTEGER', mode='required'),
]
table_ref = client.dataset('dataset_name').table('table_name')
load_config = LoadJobConfig()
load_config.skip_leading_rows = 1
load_config.schema = SCHEMA
# Contents of csv_file.csv:
# Name,Age
# Tim,99
with open('csv_file.csv', 'rb') as readable:
client.load_table_from_file(
readable, table_ref, job_config=load_config) # API request
Perform a query
# Perform a query.
QUERY = (
'SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` '
'WHERE state = "TX" '
'LIMIT 100')
query_job = client.query(QUERY) # API request
rows = query_job.result() # Waits for query to finish
for row in rows:
print(row.name)
See the google-cloud-python API BigQuery documentation to learn how to connect to BigQuery using this Client Library.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for google-cloud-bigquery-0.31.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6374a68ef232ae93b6bc364e62c37c9e2bc1fffdd017ea10ffe6a65393f40acb |
|
MD5 | 0cccfb112bedf4d3dae08e814b04d72b |
|
BLAKE2b-256 | da9a650a3a34cfa75c8f4809f5493a394e380c79bd1f3da335a3f9801f8601dc |
Hashes for google_cloud_bigquery-0.31.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dfb9b2819d5731a42e7e5e003938be7ceda66b40c8ffb67a44073d45aca94b7a |
|
MD5 | 0e4fd56525a2029b86832efe9c177816 |
|
BLAKE2b-256 | 6ba1923a1ef4fcbbb973ae3732efac0def7e8512c8b36a1435cee525e076f68d |