1# Copyright 2015 Google LLC
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
17The main concepts with this API are:
18
19- :class:`~google.cloud.bigquery.client.Client` manages connections to the
20 BigQuery API. Use the client methods to run jobs (such as a
21 :class:`~google.cloud.bigquery.job.QueryJob` via
22 :meth:`~google.cloud.bigquery.client.Client.query`) and manage resources.
23
24- :class:`~google.cloud.bigquery.dataset.Dataset` represents a
25 collection of tables.
26
27- :class:`~google.cloud.bigquery.table.Table` represents a single "relation".
28"""
29
30import warnings
31
32from google.cloud.bigquery import version as bigquery_version
33
34__version__ = bigquery_version.__version__
35
36from google.cloud.bigquery.client import Client
37from google.cloud.bigquery.dataset import AccessEntry
38from google.cloud.bigquery.dataset import Dataset
39from google.cloud.bigquery.dataset import DatasetReference
40from google.cloud.bigquery import enums
41from google.cloud.bigquery.enums import AutoRowIDs
42from google.cloud.bigquery.enums import DecimalTargetType
43from google.cloud.bigquery.enums import KeyResultStatementKind
44from google.cloud.bigquery.enums import SqlTypeNames
45from google.cloud.bigquery.enums import StandardSqlTypeNames
46from google.cloud.bigquery.exceptions import LegacyBigQueryStorageError
47from google.cloud.bigquery.exceptions import LegacyPandasError
48from google.cloud.bigquery.exceptions import LegacyPyarrowError
49from google.cloud.bigquery.external_config import ExternalConfig
50from google.cloud.bigquery.external_config import BigtableOptions
51from google.cloud.bigquery.external_config import BigtableColumnFamily
52from google.cloud.bigquery.external_config import BigtableColumn
53from google.cloud.bigquery.external_config import CSVOptions
54from google.cloud.bigquery.external_config import GoogleSheetsOptions
55from google.cloud.bigquery.external_config import ExternalSourceFormat
56from google.cloud.bigquery.external_config import HivePartitioningOptions
57from google.cloud.bigquery.format_options import AvroOptions
58from google.cloud.bigquery.format_options import ParquetOptions
59from google.cloud.bigquery.job.base import SessionInfo
60from google.cloud.bigquery.job import Compression
61from google.cloud.bigquery.job import CopyJob
62from google.cloud.bigquery.job import CopyJobConfig
63from google.cloud.bigquery.job import CreateDisposition
64from google.cloud.bigquery.job import DestinationFormat
65from google.cloud.bigquery.job import DmlStats
66from google.cloud.bigquery.job import Encoding
67from google.cloud.bigquery.job import ExtractJob
68from google.cloud.bigquery.job import ExtractJobConfig
69from google.cloud.bigquery.job import LoadJob
70from google.cloud.bigquery.job import LoadJobConfig
71from google.cloud.bigquery.job import OperationType
72from google.cloud.bigquery.job import QueryJob
73from google.cloud.bigquery.job import QueryJobConfig
74from google.cloud.bigquery.job import QueryPriority
75from google.cloud.bigquery.job import SchemaUpdateOption
76from google.cloud.bigquery.job import ScriptOptions
77from google.cloud.bigquery.job import SourceFormat
78from google.cloud.bigquery.job import UnknownJob
79from google.cloud.bigquery.job import TransactionInfo
80from google.cloud.bigquery.job import WriteDisposition
81from google.cloud.bigquery.model import Model
82from google.cloud.bigquery.model import ModelReference
83from google.cloud.bigquery.query import ArrayQueryParameter
84from google.cloud.bigquery.query import ArrayQueryParameterType
85from google.cloud.bigquery.query import ConnectionProperty
86from google.cloud.bigquery.query import ScalarQueryParameter
87from google.cloud.bigquery.query import ScalarQueryParameterType
88from google.cloud.bigquery.query import RangeQueryParameter
89from google.cloud.bigquery.query import RangeQueryParameterType
90from google.cloud.bigquery.query import SqlParameterScalarTypes
91from google.cloud.bigquery.query import StructQueryParameter
92from google.cloud.bigquery.query import StructQueryParameterType
93from google.cloud.bigquery.query import UDFResource
94from google.cloud.bigquery.retry import DEFAULT_RETRY
95from google.cloud.bigquery.routine import DeterminismLevel
96from google.cloud.bigquery.routine import Routine
97from google.cloud.bigquery.routine import RoutineArgument
98from google.cloud.bigquery.routine import RoutineReference
99from google.cloud.bigquery.routine import RoutineType
100from google.cloud.bigquery.routine import RemoteFunctionOptions
101from google.cloud.bigquery.routine import ExternalRuntimeOptions
102from google.cloud.bigquery.schema import PolicyTagList
103from google.cloud.bigquery.schema import SchemaField
104from google.cloud.bigquery.schema import FieldElementType
105from google.cloud.bigquery.standard_sql import StandardSqlDataType
106from google.cloud.bigquery.standard_sql import StandardSqlField
107from google.cloud.bigquery.standard_sql import StandardSqlStructType
108from google.cloud.bigquery.standard_sql import StandardSqlTableType
109from google.cloud.bigquery.table import PartitionRange
110from google.cloud.bigquery.table import RangePartitioning
111from google.cloud.bigquery.table import Row
112from google.cloud.bigquery.table import SnapshotDefinition
113from google.cloud.bigquery.table import CloneDefinition
114from google.cloud.bigquery.table import Table
115from google.cloud.bigquery.table import TableReference
116from google.cloud.bigquery.table import TimePartitioningType
117from google.cloud.bigquery.table import TimePartitioning
118from google.cloud.bigquery.encryption_configuration import EncryptionConfiguration
119from google.cloud.bigquery import _versions_helpers
120
121try:
122 import bigquery_magics # type: ignore
123except ImportError:
124 bigquery_magics = None
125
126sys_major, sys_minor, sys_micro = _versions_helpers.extract_runtime_version()
127
128if sys_major == 3 and sys_minor in (7, 8):
129 warnings.warn(
130 "The python-bigquery library no longer supports Python 3.7 "
131 "and Python 3.8. "
132 f"Your Python version is {sys_major}.{sys_minor}.{sys_micro}. We "
133 "recommend that you update soon to ensure ongoing support. For "
134 "more details, see: [Google Cloud Client Libraries Supported Python Versions policy](https://cloud.google.com/python/docs/supported-python-versions)",
135 FutureWarning,
136 )
137
138__all__ = [
139 "__version__",
140 "Client",
141 # Queries
142 "ConnectionProperty",
143 "QueryJob",
144 "QueryJobConfig",
145 "ArrayQueryParameter",
146 "ScalarQueryParameter",
147 "StructQueryParameter",
148 "RangeQueryParameter",
149 "ArrayQueryParameterType",
150 "ScalarQueryParameterType",
151 "SqlParameterScalarTypes",
152 "StructQueryParameterType",
153 "RangeQueryParameterType",
154 # Datasets
155 "Dataset",
156 "DatasetReference",
157 "AccessEntry",
158 # Tables
159 "Table",
160 "TableReference",
161 "PartitionRange",
162 "RangePartitioning",
163 "Row",
164 "SnapshotDefinition",
165 "CloneDefinition",
166 "TimePartitioning",
167 "TimePartitioningType",
168 # Jobs
169 "CopyJob",
170 "CopyJobConfig",
171 "ExtractJob",
172 "ExtractJobConfig",
173 "LoadJob",
174 "LoadJobConfig",
175 "SessionInfo",
176 "UnknownJob",
177 # Models
178 "Model",
179 "ModelReference",
180 # Routines
181 "Routine",
182 "RoutineArgument",
183 "RoutineReference",
184 "RemoteFunctionOptions",
185 "ExternalRuntimeOptions",
186 # Shared helpers
187 "SchemaField",
188 "FieldElementType",
189 "PolicyTagList",
190 "UDFResource",
191 "ExternalConfig",
192 "AvroOptions",
193 "BigtableOptions",
194 "BigtableColumnFamily",
195 "BigtableColumn",
196 "DmlStats",
197 "CSVOptions",
198 "GoogleSheetsOptions",
199 "HivePartitioningOptions",
200 "ParquetOptions",
201 "ScriptOptions",
202 "TransactionInfo",
203 "DEFAULT_RETRY",
204 # Standard SQL types
205 "StandardSqlDataType",
206 "StandardSqlField",
207 "StandardSqlStructType",
208 "StandardSqlTableType",
209 # Enum Constants
210 "enums",
211 "AutoRowIDs",
212 "Compression",
213 "CreateDisposition",
214 "DecimalTargetType",
215 "DestinationFormat",
216 "DeterminismLevel",
217 "ExternalSourceFormat",
218 "Encoding",
219 "KeyResultStatementKind",
220 "OperationType",
221 "QueryPriority",
222 "RoutineType",
223 "SchemaUpdateOption",
224 "SourceFormat",
225 "SqlTypeNames",
226 "StandardSqlTypeNames",
227 "WriteDisposition",
228 # EncryptionConfiguration
229 "EncryptionConfiguration",
230 # Custom exceptions
231 "LegacyBigQueryStorageError",
232 "LegacyPyarrowError",
233 "LegacyPandasError",
234]
235
236
237def load_ipython_extension(ipython):
238 """Called by IPython when this module is loaded as an IPython extension."""
239 warnings.warn(
240 "%load_ext google.cloud.bigquery is deprecated. Install bigquery-magics package and use `%load_ext bigquery_magics`, instead.",
241 category=FutureWarning,
242 )
243
244 if bigquery_magics is not None:
245 bigquery_magics.load_ipython_extension(ipython)
246 else:
247 from google.cloud.bigquery.magics.magics import _cell_magic
248
249 ipython.register_magic_function(
250 _cell_magic, magic_kind="cell", magic_name="bigquery"
251 )