Skip to content

Commit d6f65fd

Browse files
committed
Merge remote-tracking branch 'upstream/master' into bigquery-b2
1 parent f2767dd commit d6f65fd

25 files changed

+20048
-0
lines changed

bigquery/.coveragerc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[run]
2+
branch = True
3+
4+
[report]
5+
fail_under = 100
6+
show_missing = True
7+
exclude_lines =
8+
# Re-enable the standard pragma
9+
pragma: NO COVER
10+
# Ignore debug-only repr
11+
def __repr__
12+
# Ignore abstract methods
13+
raise NotImplementedError

bigquery/README.rst

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
Python Client for Google BigQuery
2+
=================================
3+
4+
Python idiomatic client for `Google BigQuery`_
5+
6+
.. _Google BigQuery: https://cloud.google.com/bigquery/what-is-bigquery
7+
8+
|pypi| |versions|
9+
10+
- `Documentation`_
11+
12+
.. _Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/usage.html
13+
14+
Quick Start
15+
-----------
16+
17+
.. code-block:: console
18+
19+
$ pip install --upgrade google-cloud-bigquery
20+
21+
Fore more information on setting up your Python development environment, such as installing ``pip`` and on your system, please refer to `Python Development Environment Setup Guide`_ for Google Cloud Platform.
22+
23+
.. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup
24+
25+
Authentication
26+
--------------
27+
28+
With ``google-cloud-python`` we try to make authentication as painless as
29+
possible. Check out the `Authentication section`_ in our documentation to
30+
learn more. You may also find the `authentication document`_ shared by all
31+
the ``google-cloud-*`` libraries to be helpful.
32+
33+
.. _Authentication section: https://google-cloud-python.readthedocs.io/en/latest/core/auth.html
34+
.. _authentication document: https://github.com/GoogleCloudPlatform/google-cloud-common/tree/master/authentication
35+
36+
Using the API
37+
-------------
38+
39+
Querying massive datasets can be time consuming and expensive without the
40+
right hardware and infrastructure. Google `BigQuery`_ (`BigQuery API docs`_)
41+
solves this problem by enabling super-fast, SQL queries against
42+
append-mostly tables, using the processing power of Google's infrastructure.
43+
44+
.. _BigQuery: https://cloud.google.com/bigquery/what-is-bigquery
45+
.. _BigQuery API docs: https://cloud.google.com/bigquery/docs/reference/v2/
46+
47+
Create a dataset
48+
~~~~~~~~~~~~~~~~
49+
50+
.. code:: python
51+
52+
from google.cloud import bigquery
53+
from google.cloud.bigquery import Dataset
54+
55+
client = bigquery.Client()
56+
57+
dataset_ref = client.dataset('dataset_name')
58+
dataset = Dataset(dataset_ref)
59+
dataset.description = 'my dataset'
60+
dataset = client.create_dataset(dataset) # API request
61+
62+
Load data from CSV
63+
~~~~~~~~~~~~~~~~~~
64+
65+
.. code:: python
66+
67+
import csv
68+
69+
from google.cloud import bigquery
70+
from google.cloud.bigquery import LoadJobConfig
71+
from google.cloud.bigquery import SchemaField
72+
73+
client = bigquery.Client()
74+
75+
SCHEMA = [
76+
SchemaField('full_name', 'STRING', mode='required'),
77+
SchemaField('age', 'INTEGER', mode='required'),
78+
]
79+
table_ref = client.dataset('dataset_name').table('table_name')
80+
81+
load_config = LoadJobConfig()
82+
load_config.skip_leading_rows = 1
83+
load_config.schema = SCHEMA
84+
85+
# Contents of csv_file.csv:
86+
# Name,Age
87+
# Tim,99
88+
with open('csv_file.csv', 'rb') as readable:
89+
client.load_table_from_file(
90+
readable, table_ref, job_config=load_config) # API request
91+
92+
Perform a query
93+
~~~~~~~~~~~~~~~
94+
95+
.. code:: python
96+
97+
# Perform a query.
98+
QUERY = (
99+
'SELECT name FROM `bigquery-public-data.usa_names.usa_1910_2013` '
100+
'WHERE state = "TX" '
101+
'LIMIT 100')
102+
query_job = client.query(QUERY) # API request
103+
rows = query_job.result() # Waits for query to finish
104+
105+
for row in rows:
106+
print(row.name)
107+
108+
109+
See the ``google-cloud-python`` API `BigQuery documentation`_ to learn how
110+
to connect to BigQuery using this Client Library.
111+
112+
.. _BigQuery documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/bigquery/usage.html
113+
114+
.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-bigquery.svg
115+
:target: https://pypi.org/project/google-cloud-bigquery/
116+
.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-bigquery.svg
117+
:target: https://pypi.org/project/google-cloud-bigquery/
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Copyright 2015 Google Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Google BigQuery API wrapper.
16+
17+
The main concepts with this API are:
18+
19+
- :class:`~google.cloud.bigquery.dataset.Dataset` represents a
20+
collection of tables.
21+
22+
- :class:`~google.cloud.bigquery.table.Table` represents a single "relation".
23+
"""
24+
25+
26+
from pkg_resources import get_distribution
27+
__version__ = get_distribution('google-cloud-bigquery').version
28+
29+
from google.cloud.bigquery._helpers import Row
30+
from google.cloud.bigquery._helpers import DEFAULT_RETRY
31+
from google.cloud.bigquery.client import Client
32+
from google.cloud.bigquery.dataset import AccessEntry
33+
from google.cloud.bigquery.dataset import Dataset
34+
from google.cloud.bigquery.dataset import DatasetReference
35+
from google.cloud.bigquery.job import CopyJobConfig
36+
from google.cloud.bigquery.job import ExtractJobConfig
37+
from google.cloud.bigquery.job import QueryJobConfig
38+
from google.cloud.bigquery.job import LoadJobConfig
39+
from google.cloud.bigquery.query import ArrayQueryParameter
40+
from google.cloud.bigquery.query import ScalarQueryParameter
41+
from google.cloud.bigquery.query import StructQueryParameter
42+
from google.cloud.bigquery.query import UDFResource
43+
from google.cloud.bigquery.schema import SchemaField
44+
from google.cloud.bigquery.table import Table
45+
from google.cloud.bigquery.table import TableReference
46+
from google.cloud.bigquery.external_config import ExternalConfig
47+
from google.cloud.bigquery.external_config import BigtableOptions
48+
from google.cloud.bigquery.external_config import BigtableColumnFamily
49+
from google.cloud.bigquery.external_config import BigtableColumn
50+
from google.cloud.bigquery.external_config import CSVOptions
51+
from google.cloud.bigquery.external_config import GoogleSheetsOptions
52+
53+
__all__ = [
54+
'__version__',
55+
'AccessEntry',
56+
'ArrayQueryParameter',
57+
'Client',
58+
'Dataset',
59+
'DatasetReference',
60+
'CopyJobConfig',
61+
'ExtractJobConfig',
62+
'QueryJobConfig',
63+
'Row',
64+
'LoadJobConfig',
65+
'ScalarQueryParameter',
66+
'SchemaField',
67+
'StructQueryParameter',
68+
'Table',
69+
'TableReference',
70+
'UDFResource',
71+
'DEFAULT_RETRY',
72+
'ExternalConfig',
73+
'BigtableOptions',
74+
'BigtableColumnFamily',
75+
'BigtableColumn',
76+
'CSVOptions',
77+
'GoogleSheetsOptions',
78+
]

0 commit comments

Comments
 (0)