Please note that the contents of this offline web site may be out of date. To access the most recent documentation visit the online version .
Note that links that point to online resources are green in color and will open in a new window.
We would love it if you could give us feedback about this material by filling this form (You have to be online to fill it)



API Overview (V2)

The API Overview section describes how to use the BigQuery API and is broken up into different pages for different types of tasks. This document describes how to get started using the API. After reviewing this page, be sure to read authorizing access and the remaining sections of the API overview.

Contents

Getting Started

BigQuery provides a REST-based API that can be accessed programmatically from a variety of languages. The recommended way to access the BigQuery API is through one of the Google API Client libraries . This API overview uses the Python client library and the Java client library and provides samples in both languages.

Prerequisites

Before you can use the BigQuery API, you must:

  • Activate the BigQuery API

    If you are a member of an existing Google APIs Console project that already has BigQuery enabled, you can use that project to build your application. To learn how to sign up for BigQuery, check out our sign up process .

If you want to run the samples provided in this overview, you must:

  • Download and install client libraries

    Download and install either the Java client library or the Python client library .

  • Be able to write basic Java or Python code

    The samples in this overview assume that you have basic coding knowledge.

Authorizing Access to the BigQuery API

The BigQuery API requires all requests to be authorized by an authenticated user or a service account. We strongly recommend that your application use the OAuth 2.0 protocol to authorize requests to the BigQuery API. OAuth provides authorization flows for web, desktop, mobile, server-based and even embedded device applications.

Before you write any code , read our guide to authorizing access to the BigQuery API .

Authorizing access to the BigQuery API requires using the following scope:

Scope Meaning
https://www.googleapis.com/auth/bigquery View and manage data in Google BigQuery
https://www.googleapis.com/auth/bigquery.readonly View data in Google BigQuery

To request access using OAuth 2.0, your application needs the scope information, as well as information that Google supplies during application registration (such as the client ID and/or the client secret).

Instantiating a BigQuery API service object

After your choosing an authorization method and retrieving a credential to access BigQuery, you can instantiate a service class to make calls to the API. We strongly recommend that you use one of the Google client libraries for this purpose.

BigQuery Service Object Examples

Java

This sample uses the Google APIs Client Library for Java .

import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson.JacksonFactory;
import com.google.api.services.bigquery.Bigquery;

//...

class MyClass {

  //...

  private static final HttpTransport TRANSPORT = new NetHttpTransport();
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();

  Bigquery bigquery = new Bigquery.Builder(TRANSPORT, JSON_FACTORY, credential)
    .setApplicationName("Your User Agent String Here")
    .setHttpRequestInitializer(credential).build();

}
  

JavaScript

This sample uses the Google APIs Client Library for JavaScript .

<script src="https://apis.google.com/js/client.js"></script>

<script>
var config = {'client_id': client_id,
              'scope': 'https://www.googleapis.com/auth/bigquery'
};

gapi.auth.authorize(config, function() {
    gapi.client.load('bigquery', 'v2');
});
</script>
  

Python

This sample uses the Google APIs Client Library for Python .

import httplib2

from apiclient import errors
from apiclient.discovery import build
#...

http = credentials.authorize(http)
service = build('bigquery', 'v2')
  

Back to top

Next Steps

When you're ready to start using the API:

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.