• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1"""Generated client library for bigquery version v2."""
2# NOTE: This file is autogenerated and should not be edited by hand.
3
4from __future__ import absolute_import
5
6from apitools.base.py import base_api
7from samples.bigquery_sample.bigquery_v2 import bigquery_v2_messages as messages
8
9
10class BigqueryV2(base_api.BaseApiClient):
11  """Generated client library for service bigquery version v2."""
12
13  MESSAGES_MODULE = messages
14  BASE_URL = 'https://www.googleapis.com/bigquery/v2/'
15  MTLS_BASE_URL = ''
16
17  _PACKAGE = 'bigquery'
18  _SCOPES = ['https://www.googleapis.com/auth/bigquery', 'https://www.googleapis.com/auth/bigquery.insertdata', 'https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/cloud-platform.read-only', 'https://www.googleapis.com/auth/devstorage.full_control', 'https://www.googleapis.com/auth/devstorage.read_only', 'https://www.googleapis.com/auth/devstorage.read_write']
19  _VERSION = 'v2'
20  _CLIENT_ID = 'CLIENT_ID'
21  _CLIENT_SECRET = 'CLIENT_SECRET'
22  _USER_AGENT = 'x_Tw5K8nnjoRAqULM9PFAC2b'
23  _CLIENT_CLASS_NAME = 'BigqueryV2'
24  _URL_VERSION = 'v2'
25  _API_KEY = None
26
27  def __init__(self, url='', credentials=None,
28               get_credentials=True, http=None, model=None,
29               log_request=False, log_response=False,
30               credentials_args=None, default_global_params=None,
31               additional_http_headers=None, response_encoding=None):
32    """Create a new bigquery handle."""
33    url = url or self.BASE_URL
34    super(BigqueryV2, self).__init__(
35        url, credentials=credentials,
36        get_credentials=get_credentials, http=http, model=model,
37        log_request=log_request, log_response=log_response,
38        credentials_args=credentials_args,
39        default_global_params=default_global_params,
40        additional_http_headers=additional_http_headers,
41        response_encoding=response_encoding)
42    self.datasets = self.DatasetsService(self)
43    self.jobs = self.JobsService(self)
44    self.projects = self.ProjectsService(self)
45    self.tabledata = self.TabledataService(self)
46    self.tables = self.TablesService(self)
47
48  class DatasetsService(base_api.BaseApiService):
49    """Service class for the datasets resource."""
50
51    _NAME = 'datasets'
52
53    def __init__(self, client):
54      super(BigqueryV2.DatasetsService, self).__init__(client)
55      self._upload_configs = {
56          }
57
58    def Delete(self, request, global_params=None):
59      r"""Deletes the dataset specified by the datasetId value. Before you can delete a dataset, you must delete all its tables, either manually or by specifying deleteContents. Immediately after deletion, you can create another dataset with the same name.
60
61      Args:
62        request: (BigqueryDatasetsDeleteRequest) input message
63        global_params: (StandardQueryParameters, default: None) global arguments
64      Returns:
65        (BigqueryDatasetsDeleteResponse) The response message.
66      """
67      config = self.GetMethodConfig('Delete')
68      return self._RunMethod(
69          config, request, global_params=global_params)
70
71    Delete.method_config = lambda: base_api.ApiMethodInfo(
72        http_method='DELETE',
73        method_id='bigquery.datasets.delete',
74        ordered_params=['projectId', 'datasetId'],
75        path_params=['datasetId', 'projectId'],
76        query_params=['deleteContents'],
77        relative_path='projects/{projectId}/datasets/{datasetId}',
78        request_field='',
79        request_type_name='BigqueryDatasetsDeleteRequest',
80        response_type_name='BigqueryDatasetsDeleteResponse',
81        supports_download=False,
82    )
83
84    def Get(self, request, global_params=None):
85      r"""Returns the dataset specified by datasetID.
86
87      Args:
88        request: (BigqueryDatasetsGetRequest) input message
89        global_params: (StandardQueryParameters, default: None) global arguments
90      Returns:
91        (Dataset) The response message.
92      """
93      config = self.GetMethodConfig('Get')
94      return self._RunMethod(
95          config, request, global_params=global_params)
96
97    Get.method_config = lambda: base_api.ApiMethodInfo(
98        http_method='GET',
99        method_id='bigquery.datasets.get',
100        ordered_params=['projectId', 'datasetId'],
101        path_params=['datasetId', 'projectId'],
102        query_params=[],
103        relative_path='projects/{projectId}/datasets/{datasetId}',
104        request_field='',
105        request_type_name='BigqueryDatasetsGetRequest',
106        response_type_name='Dataset',
107        supports_download=False,
108    )
109
110    def Insert(self, request, global_params=None):
111      r"""Creates a new empty dataset.
112
113      Args:
114        request: (BigqueryDatasetsInsertRequest) input message
115        global_params: (StandardQueryParameters, default: None) global arguments
116      Returns:
117        (Dataset) The response message.
118      """
119      config = self.GetMethodConfig('Insert')
120      return self._RunMethod(
121          config, request, global_params=global_params)
122
123    Insert.method_config = lambda: base_api.ApiMethodInfo(
124        http_method='POST',
125        method_id='bigquery.datasets.insert',
126        ordered_params=['projectId'],
127        path_params=['projectId'],
128        query_params=[],
129        relative_path='projects/{projectId}/datasets',
130        request_field='dataset',
131        request_type_name='BigqueryDatasetsInsertRequest',
132        response_type_name='Dataset',
133        supports_download=False,
134    )
135
136    def List(self, request, global_params=None):
137      r"""Lists all datasets in the specified project to which you have been granted the READER dataset role.
138
139      Args:
140        request: (BigqueryDatasetsListRequest) input message
141        global_params: (StandardQueryParameters, default: None) global arguments
142      Returns:
143        (DatasetList) The response message.
144      """
145      config = self.GetMethodConfig('List')
146      return self._RunMethod(
147          config, request, global_params=global_params)
148
149    List.method_config = lambda: base_api.ApiMethodInfo(
150        http_method='GET',
151        method_id='bigquery.datasets.list',
152        ordered_params=['projectId'],
153        path_params=['projectId'],
154        query_params=['all', 'filter', 'maxResults', 'pageToken'],
155        relative_path='projects/{projectId}/datasets',
156        request_field='',
157        request_type_name='BigqueryDatasetsListRequest',
158        response_type_name='DatasetList',
159        supports_download=False,
160    )
161
162    def Patch(self, request, global_params=None):
163      r"""Updates information in an existing dataset. The update method replaces the entire dataset resource, whereas the patch method only replaces fields that are provided in the submitted dataset resource. This method supports patch semantics.
164
165      Args:
166        request: (BigqueryDatasetsPatchRequest) input message
167        global_params: (StandardQueryParameters, default: None) global arguments
168      Returns:
169        (Dataset) The response message.
170      """
171      config = self.GetMethodConfig('Patch')
172      return self._RunMethod(
173          config, request, global_params=global_params)
174
175    Patch.method_config = lambda: base_api.ApiMethodInfo(
176        http_method='PATCH',
177        method_id='bigquery.datasets.patch',
178        ordered_params=['projectId', 'datasetId'],
179        path_params=['datasetId', 'projectId'],
180        query_params=[],
181        relative_path='projects/{projectId}/datasets/{datasetId}',
182        request_field='dataset',
183        request_type_name='BigqueryDatasetsPatchRequest',
184        response_type_name='Dataset',
185        supports_download=False,
186    )
187
188    def Update(self, request, global_params=None):
189      r"""Updates information in an existing dataset. The update method replaces the entire dataset resource, whereas the patch method only replaces fields that are provided in the submitted dataset resource.
190
191      Args:
192        request: (BigqueryDatasetsUpdateRequest) input message
193        global_params: (StandardQueryParameters, default: None) global arguments
194      Returns:
195        (Dataset) The response message.
196      """
197      config = self.GetMethodConfig('Update')
198      return self._RunMethod(
199          config, request, global_params=global_params)
200
201    Update.method_config = lambda: base_api.ApiMethodInfo(
202        http_method='PUT',
203        method_id='bigquery.datasets.update',
204        ordered_params=['projectId', 'datasetId'],
205        path_params=['datasetId', 'projectId'],
206        query_params=[],
207        relative_path='projects/{projectId}/datasets/{datasetId}',
208        request_field='dataset',
209        request_type_name='BigqueryDatasetsUpdateRequest',
210        response_type_name='Dataset',
211        supports_download=False,
212    )
213
214  class JobsService(base_api.BaseApiService):
215    """Service class for the jobs resource."""
216
217    _NAME = 'jobs'
218
219    def __init__(self, client):
220      super(BigqueryV2.JobsService, self).__init__(client)
221      self._upload_configs = {
222          'Insert': base_api.ApiUploadInfo(
223              accept=['*/*'],
224              max_size=None,
225              resumable_multipart=True,
226              resumable_path='/resumable/upload/bigquery/v2/projects/{projectId}/jobs',
227              simple_multipart=True,
228              simple_path='/upload/bigquery/v2/projects/{projectId}/jobs',
229          ),
230          }
231
232    def Cancel(self, request, global_params=None):
233      r"""Requests that a job be cancelled. This call will return immediately, and the client will need to poll for the job status to see if the cancel completed successfully. Cancelled jobs may still incur costs.
234
235      Args:
236        request: (BigqueryJobsCancelRequest) input message
237        global_params: (StandardQueryParameters, default: None) global arguments
238      Returns:
239        (JobCancelResponse) The response message.
240      """
241      config = self.GetMethodConfig('Cancel')
242      return self._RunMethod(
243          config, request, global_params=global_params)
244
245    Cancel.method_config = lambda: base_api.ApiMethodInfo(
246        http_method='POST',
247        method_id='bigquery.jobs.cancel',
248        ordered_params=['projectId', 'jobId'],
249        path_params=['jobId', 'projectId'],
250        query_params=[],
251        relative_path='project/{projectId}/jobs/{jobId}/cancel',
252        request_field='',
253        request_type_name='BigqueryJobsCancelRequest',
254        response_type_name='JobCancelResponse',
255        supports_download=False,
256    )
257
258    def Get(self, request, global_params=None):
259      r"""Returns information about a specific job. Job information is available for a six month period after creation. Requires that you're the person who ran the job, or have the Is Owner project role.
260
261      Args:
262        request: (BigqueryJobsGetRequest) input message
263        global_params: (StandardQueryParameters, default: None) global arguments
264      Returns:
265        (Job) The response message.
266      """
267      config = self.GetMethodConfig('Get')
268      return self._RunMethod(
269          config, request, global_params=global_params)
270
271    Get.method_config = lambda: base_api.ApiMethodInfo(
272        http_method='GET',
273        method_id='bigquery.jobs.get',
274        ordered_params=['projectId', 'jobId'],
275        path_params=['jobId', 'projectId'],
276        query_params=[],
277        relative_path='projects/{projectId}/jobs/{jobId}',
278        request_field='',
279        request_type_name='BigqueryJobsGetRequest',
280        response_type_name='Job',
281        supports_download=False,
282    )
283
284    def GetQueryResults(self, request, global_params=None):
285      r"""Retrieves the results of a query job.
286
287      Args:
288        request: (BigqueryJobsGetQueryResultsRequest) input message
289        global_params: (StandardQueryParameters, default: None) global arguments
290      Returns:
291        (GetQueryResultsResponse) The response message.
292      """
293      config = self.GetMethodConfig('GetQueryResults')
294      return self._RunMethod(
295          config, request, global_params=global_params)
296
297    GetQueryResults.method_config = lambda: base_api.ApiMethodInfo(
298        http_method='GET',
299        method_id='bigquery.jobs.getQueryResults',
300        ordered_params=['projectId', 'jobId'],
301        path_params=['jobId', 'projectId'],
302        query_params=['maxResults', 'pageToken', 'startIndex', 'timeoutMs'],
303        relative_path='projects/{projectId}/queries/{jobId}',
304        request_field='',
305        request_type_name='BigqueryJobsGetQueryResultsRequest',
306        response_type_name='GetQueryResultsResponse',
307        supports_download=False,
308    )
309
310    def Insert(self, request, global_params=None, upload=None):
311      r"""Starts a new asynchronous job. Requires the Can View project role.
312
313      Args:
314        request: (BigqueryJobsInsertRequest) input message
315        global_params: (StandardQueryParameters, default: None) global arguments
316        upload: (Upload, default: None) If present, upload
317            this stream with the request.
318      Returns:
319        (Job) The response message.
320      """
321      config = self.GetMethodConfig('Insert')
322      upload_config = self.GetUploadConfig('Insert')
323      return self._RunMethod(
324          config, request, global_params=global_params,
325          upload=upload, upload_config=upload_config)
326
327    Insert.method_config = lambda: base_api.ApiMethodInfo(
328        http_method='POST',
329        method_id='bigquery.jobs.insert',
330        ordered_params=['projectId'],
331        path_params=['projectId'],
332        query_params=[],
333        relative_path='projects/{projectId}/jobs',
334        request_field='job',
335        request_type_name='BigqueryJobsInsertRequest',
336        response_type_name='Job',
337        supports_download=False,
338    )
339
340    def List(self, request, global_params=None):
341      r"""Lists all jobs that you started in the specified project. Job information is available for a six month period after creation. The job list is sorted in reverse chronological order, by job creation time. Requires the Can View project role, or the Is Owner project role if you set the allUsers property.
342
343      Args:
344        request: (BigqueryJobsListRequest) input message
345        global_params: (StandardQueryParameters, default: None) global arguments
346      Returns:
347        (JobList) The response message.
348      """
349      config = self.GetMethodConfig('List')
350      return self._RunMethod(
351          config, request, global_params=global_params)
352
353    List.method_config = lambda: base_api.ApiMethodInfo(
354        http_method='GET',
355        method_id='bigquery.jobs.list',
356        ordered_params=['projectId'],
357        path_params=['projectId'],
358        query_params=['allUsers', 'maxResults', 'pageToken', 'projection', 'stateFilter'],
359        relative_path='projects/{projectId}/jobs',
360        request_field='',
361        request_type_name='BigqueryJobsListRequest',
362        response_type_name='JobList',
363        supports_download=False,
364    )
365
366    def Query(self, request, global_params=None):
367      r"""Runs a BigQuery SQL query synchronously and returns query results if the query completes within a specified timeout.
368
369      Args:
370        request: (BigqueryJobsQueryRequest) input message
371        global_params: (StandardQueryParameters, default: None) global arguments
372      Returns:
373        (QueryResponse) The response message.
374      """
375      config = self.GetMethodConfig('Query')
376      return self._RunMethod(
377          config, request, global_params=global_params)
378
379    Query.method_config = lambda: base_api.ApiMethodInfo(
380        http_method='POST',
381        method_id='bigquery.jobs.query',
382        ordered_params=['projectId'],
383        path_params=['projectId'],
384        query_params=[],
385        relative_path='projects/{projectId}/queries',
386        request_field='queryRequest',
387        request_type_name='BigqueryJobsQueryRequest',
388        response_type_name='QueryResponse',
389        supports_download=False,
390    )
391
392  class ProjectsService(base_api.BaseApiService):
393    """Service class for the projects resource."""
394
395    _NAME = 'projects'
396
397    def __init__(self, client):
398      super(BigqueryV2.ProjectsService, self).__init__(client)
399      self._upload_configs = {
400          }
401
402    def List(self, request, global_params=None):
403      r"""Lists all projects to which you have been granted any project role.
404
405      Args:
406        request: (BigqueryProjectsListRequest) input message
407        global_params: (StandardQueryParameters, default: None) global arguments
408      Returns:
409        (ProjectList) The response message.
410      """
411      config = self.GetMethodConfig('List')
412      return self._RunMethod(
413          config, request, global_params=global_params)
414
415    List.method_config = lambda: base_api.ApiMethodInfo(
416        http_method='GET',
417        method_id='bigquery.projects.list',
418        ordered_params=[],
419        path_params=[],
420        query_params=['maxResults', 'pageToken'],
421        relative_path='projects',
422        request_field='',
423        request_type_name='BigqueryProjectsListRequest',
424        response_type_name='ProjectList',
425        supports_download=False,
426    )
427
428  class TabledataService(base_api.BaseApiService):
429    """Service class for the tabledata resource."""
430
431    _NAME = 'tabledata'
432
433    def __init__(self, client):
434      super(BigqueryV2.TabledataService, self).__init__(client)
435      self._upload_configs = {
436          }
437
438    def InsertAll(self, request, global_params=None):
439      r"""Streams data into BigQuery one record at a time without needing to run a load job. Requires the WRITER dataset role.
440
441      Args:
442        request: (BigqueryTabledataInsertAllRequest) input message
443        global_params: (StandardQueryParameters, default: None) global arguments
444      Returns:
445        (TableDataInsertAllResponse) The response message.
446      """
447      config = self.GetMethodConfig('InsertAll')
448      return self._RunMethod(
449          config, request, global_params=global_params)
450
451    InsertAll.method_config = lambda: base_api.ApiMethodInfo(
452        http_method='POST',
453        method_id='bigquery.tabledata.insertAll',
454        ordered_params=['projectId', 'datasetId', 'tableId'],
455        path_params=['datasetId', 'projectId', 'tableId'],
456        query_params=[],
457        relative_path='projects/{projectId}/datasets/{datasetId}/tables/{tableId}/insertAll',
458        request_field='tableDataInsertAllRequest',
459        request_type_name='BigqueryTabledataInsertAllRequest',
460        response_type_name='TableDataInsertAllResponse',
461        supports_download=False,
462    )
463
464    def List(self, request, global_params=None):
465      r"""Retrieves table data from a specified set of rows. Requires the READER dataset role.
466
467      Args:
468        request: (BigqueryTabledataListRequest) input message
469        global_params: (StandardQueryParameters, default: None) global arguments
470      Returns:
471        (TableDataList) The response message.
472      """
473      config = self.GetMethodConfig('List')
474      return self._RunMethod(
475          config, request, global_params=global_params)
476
477    List.method_config = lambda: base_api.ApiMethodInfo(
478        http_method='GET',
479        method_id='bigquery.tabledata.list',
480        ordered_params=['projectId', 'datasetId', 'tableId'],
481        path_params=['datasetId', 'projectId', 'tableId'],
482        query_params=['maxResults', 'pageToken', 'startIndex'],
483        relative_path='projects/{projectId}/datasets/{datasetId}/tables/{tableId}/data',
484        request_field='',
485        request_type_name='BigqueryTabledataListRequest',
486        response_type_name='TableDataList',
487        supports_download=False,
488    )
489
490  class TablesService(base_api.BaseApiService):
491    """Service class for the tables resource."""
492
493    _NAME = 'tables'
494
495    def __init__(self, client):
496      super(BigqueryV2.TablesService, self).__init__(client)
497      self._upload_configs = {
498          }
499
500    def Delete(self, request, global_params=None):
501      r"""Deletes the table specified by tableId from the dataset. If the table contains data, all the data will be deleted.
502
503      Args:
504        request: (BigqueryTablesDeleteRequest) input message
505        global_params: (StandardQueryParameters, default: None) global arguments
506      Returns:
507        (BigqueryTablesDeleteResponse) The response message.
508      """
509      config = self.GetMethodConfig('Delete')
510      return self._RunMethod(
511          config, request, global_params=global_params)
512
513    Delete.method_config = lambda: base_api.ApiMethodInfo(
514        http_method='DELETE',
515        method_id='bigquery.tables.delete',
516        ordered_params=['projectId', 'datasetId', 'tableId'],
517        path_params=['datasetId', 'projectId', 'tableId'],
518        query_params=[],
519        relative_path='projects/{projectId}/datasets/{datasetId}/tables/{tableId}',
520        request_field='',
521        request_type_name='BigqueryTablesDeleteRequest',
522        response_type_name='BigqueryTablesDeleteResponse',
523        supports_download=False,
524    )
525
526    def Get(self, request, global_params=None):
527      r"""Gets the specified table resource by table ID. This method does not return the data in the table, it only returns the table resource, which describes the structure of this table.
528
529      Args:
530        request: (BigqueryTablesGetRequest) input message
531        global_params: (StandardQueryParameters, default: None) global arguments
532      Returns:
533        (Table) The response message.
534      """
535      config = self.GetMethodConfig('Get')
536      return self._RunMethod(
537          config, request, global_params=global_params)
538
539    Get.method_config = lambda: base_api.ApiMethodInfo(
540        http_method='GET',
541        method_id='bigquery.tables.get',
542        ordered_params=['projectId', 'datasetId', 'tableId'],
543        path_params=['datasetId', 'projectId', 'tableId'],
544        query_params=[],
545        relative_path='projects/{projectId}/datasets/{datasetId}/tables/{tableId}',
546        request_field='',
547        request_type_name='BigqueryTablesGetRequest',
548        response_type_name='Table',
549        supports_download=False,
550    )
551
552    def Insert(self, request, global_params=None):
553      r"""Creates a new, empty table in the dataset.
554
555      Args:
556        request: (BigqueryTablesInsertRequest) input message
557        global_params: (StandardQueryParameters, default: None) global arguments
558      Returns:
559        (Table) The response message.
560      """
561      config = self.GetMethodConfig('Insert')
562      return self._RunMethod(
563          config, request, global_params=global_params)
564
565    Insert.method_config = lambda: base_api.ApiMethodInfo(
566        http_method='POST',
567        method_id='bigquery.tables.insert',
568        ordered_params=['projectId', 'datasetId'],
569        path_params=['datasetId', 'projectId'],
570        query_params=[],
571        relative_path='projects/{projectId}/datasets/{datasetId}/tables',
572        request_field='table',
573        request_type_name='BigqueryTablesInsertRequest',
574        response_type_name='Table',
575        supports_download=False,
576    )
577
578    def List(self, request, global_params=None):
579      r"""Lists all tables in the specified dataset. Requires the READER dataset role.
580
581      Args:
582        request: (BigqueryTablesListRequest) input message
583        global_params: (StandardQueryParameters, default: None) global arguments
584      Returns:
585        (TableList) The response message.
586      """
587      config = self.GetMethodConfig('List')
588      return self._RunMethod(
589          config, request, global_params=global_params)
590
591    List.method_config = lambda: base_api.ApiMethodInfo(
592        http_method='GET',
593        method_id='bigquery.tables.list',
594        ordered_params=['projectId', 'datasetId'],
595        path_params=['datasetId', 'projectId'],
596        query_params=['maxResults', 'pageToken'],
597        relative_path='projects/{projectId}/datasets/{datasetId}/tables',
598        request_field='',
599        request_type_name='BigqueryTablesListRequest',
600        response_type_name='TableList',
601        supports_download=False,
602    )
603
604    def Patch(self, request, global_params=None):
605      r"""Updates information in an existing table. The update method replaces the entire table resource, whereas the patch method only replaces fields that are provided in the submitted table resource. This method supports patch semantics.
606
607      Args:
608        request: (BigqueryTablesPatchRequest) input message
609        global_params: (StandardQueryParameters, default: None) global arguments
610      Returns:
611        (Table) The response message.
612      """
613      config = self.GetMethodConfig('Patch')
614      return self._RunMethod(
615          config, request, global_params=global_params)
616
617    Patch.method_config = lambda: base_api.ApiMethodInfo(
618        http_method='PATCH',
619        method_id='bigquery.tables.patch',
620        ordered_params=['projectId', 'datasetId', 'tableId'],
621        path_params=['datasetId', 'projectId', 'tableId'],
622        query_params=[],
623        relative_path='projects/{projectId}/datasets/{datasetId}/tables/{tableId}',
624        request_field='table',
625        request_type_name='BigqueryTablesPatchRequest',
626        response_type_name='Table',
627        supports_download=False,
628    )
629
630    def Update(self, request, global_params=None):
631      r"""Updates information in an existing table. The update method replaces the entire table resource, whereas the patch method only replaces fields that are provided in the submitted table resource.
632
633      Args:
634        request: (BigqueryTablesUpdateRequest) input message
635        global_params: (StandardQueryParameters, default: None) global arguments
636      Returns:
637        (Table) The response message.
638      """
639      config = self.GetMethodConfig('Update')
640      return self._RunMethod(
641          config, request, global_params=global_params)
642
643    Update.method_config = lambda: base_api.ApiMethodInfo(
644        http_method='PUT',
645        method_id='bigquery.tables.update',
646        ordered_params=['projectId', 'datasetId', 'tableId'],
647        path_params=['datasetId', 'projectId', 'tableId'],
648        query_params=[],
649        relative_path='projects/{projectId}/datasets/{datasetId}/tables/{tableId}',
650        request_field='table',
651        request_type_name='BigqueryTablesUpdateRequest',
652        response_type_name='Table',
653        supports_download=False,
654    )
655