Skip to main content

Python Client for Google BigQuery

Project description

Python idiomatic client for Google BigQuery

pypi versions

Quick Start

$ pip install --upgrade google-cloud-bigquery

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-like queries against append-only tables, using the processing power of Google’s infrastructure.

Load data from CSV

import csv

from google.cloud import bigquery
from google.cloud.bigquery import SchemaField

client = bigquery.Client()

dataset = client.dataset('dataset_name')
dataset.create()  # API request

SCHEMA = [
    SchemaField('full_name', 'STRING', mode='required'),
    SchemaField('age', 'INTEGER', mode='required'),
]
table = dataset.table('table_name', SCHEMA)
table.create()

with open('csv_file', 'rb') as readable:
    table.upload_from_file(
        readable, source_format='CSV', skip_leading_rows=1)

Perform a synchronous query

# Perform a synchronous query.
QUERY = (
    'SELECT name FROM [bigquery-public-data:usa_names.usa_1910_2013] '
    'WHERE state = "TX"')
query = client.run_sync_query('%s LIMIT 100' % QUERY)
query.timeout_ms = TIMEOUT_MS
query.run()

for row in query.rows:
    print(row)

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

google-cloud-bigquery-0.21.0.tar.gz (51.5 kB view details)

Uploaded Source

Built Distribution

google_cloud_bigquery-0.21.0-py2.py3-none-any.whl (69.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file google-cloud-bigquery-0.21.0.tar.gz.

File metadata

File hashes

Hashes for google-cloud-bigquery-0.21.0.tar.gz
Algorithm Hash digest
SHA256 5c8447059a64f5af0f64ed79e0a64d56dfe7619fafb61c194671b21f058fc31d
MD5 332b2bde76d861e3cc632af50c90cc5c
BLAKE2b-256 49690cfbc3bc0b1db9149542da576fc01c4fd048622d34b1e2583475e09100b3

See more details on using hashes here.

Provenance

File details

Details for the file google_cloud_bigquery-0.21.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for google_cloud_bigquery-0.21.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 468365025bc90e8c3abd3cdf112af471ac417a11cc2d527cdbbb979ba7773cef
MD5 338e2a39aebf828832b2c277f26c15e5
BLAKE2b-256 f5f299067921a4e34426d6291c0bbe01955ba9f00aa426f3e9801d9c9a38e39a

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page