Created
February 24, 2026 12:50
-
-
Save GeroZayas/e567aad9c652576a17b55512fc1c2712 to your computer and use it in GitHub Desktop.
Create a BigQuery client with a service account key file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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