python-bigquery-dataframes icon indicating copy to clipboard operation
python-bigquery-dataframes copied to clipboard

Add service account authentication in bigframes `read_gbq` method like in pandas-gbq package

Open Et9797 opened this issue 1 year ago • 1 comments

Very simple in pandas-gbq:

from google.oauth2 import service_account
import pandas_gbq

credentials = service_account.Credentials.from_service_account_file('
    path/to/key.json'
)
df = pandas_gbq.read_gbq(query, project_id="YOUR-PROJECT-ID", credentials=credentials)

Et9797 avatar May 22 '24 14:05 Et9797

Thanks for the feature request!

This is currently possible using the bigframes.options.bigquery.credentials property:

from google.oauth2 import service_account
import bigframes.pandas as bpd

credentials = service_account.Credentials.from_service_account_file('
    path/to/key.json'
)
bpd.options.bigquery.project = "YOUR-PROJECT-ID"
bpd.options.bigquery.credentials = credentials
df = bpd.read_gbq(query)

That said, I think it makes sense to try and stay compatible with pandas-gbq usage. We already do something similar to this for autodetecting the location when read_gbq is the first call in a new BigQuery DataFrames session.

tswast avatar May 22 '24 14:05 tswast