Google BigQuery API client library
Project description
Querying massive datasets can be time consuming and expensive without the right hardware and infrastructure. Google BigQuery solves this problem by enabling super-fast, SQL queries against append-mostly tables, using the processing power of Google’s infrastructure.
Quick Start
In order to use this library, you first need to go through the following steps:
Installation
Install this library in a virtualenv using pip. virtualenv is a tool to create isolated Python environments. The basic problem it addresses is one of dependencies and versions, and indirectly permissions.
With virtualenv, it’s possible to install this library without needing system install permissions, and without clashing with the installed system dependencies.
Mac/Linux
pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-cloud-bigquery
Windows
pip install virtualenv
virtualenv <your-env>
<your-env>\Scripts\activate
<your-env>\Scripts\pip.exe install google-cloud-bigquery
Example Usage
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)
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-1.6.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04f0a2bb53d779fc62927be92f8253c34774a1a9f95cccec3e45d000d1547ef9 |
|
MD5 | b69d9dcbc1065ec565f24977a0daf700 |
|
BLAKE2b-256 | 5d327df41e8ef0b7661089b4c063ff60f987f7987990f54ae684c75908a0d5d0 |
Hashes for google_cloud_bigquery-1.6.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbdc436f6afb00e62a41af011b987bb9a107571c8647dc0264d232e0efe94810 |
|
MD5 | 0ede7c1c14e82d34efb08f1713007d3c |
|
BLAKE2b-256 | b71b2b95f2fefddbbece38110712c225bfb5649206f4056445653bd5ca4dc86d |