Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save GeroZayas/e567aad9c652576a17b55512fc1c2712 to your computer and use it in GitHub Desktop.

Select an option

Save GeroZayas/e567aad9c652576a17b55512fc1c2712 to your computer and use it in GitHub Desktop.
Create a BigQuery client with a service account key file
from google.cloud import bigquery
from google.oauth2 import service_account
# TODO(developer): Set key_path to the path to the service account key
# file.
# key_path = "path/to/service_account.json"
credentials = service_account.Credentials.from_service_account_file(
key_path,
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
# Alternatively, use service_account.Credentials.from_service_account_info()
# to set credentials directly via a json object rather than set a filepath
# TODO(developer): Set key_json to the content of the service account key file.
# credentials = service_account.Credentials.from_service_account_info(key_json)
client = bigquery.Client(
credentials=credentials,
project=credentials.project_id,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment