Is your feature request related to a problem? Please describe.
The Google Cloud Ready - BigQuery partnership program requires partners to set a custom UserAgent. This is so Google can correctly attribute usage. However, there is no built in way to set the UserAgent in this library. It's hardcoded to sqlalchemy right now.
|
def google_client_info(): |
|
user_agent = USER_AGENT_TEMPLATE.format(sqlalchemy.__version__) |
|
return client_info.ClientInfo(user_agent=user_agent) |
|
|
|
|
|
def create_bigquery_client( |
|
credentials_info=None, |
|
credentials_path=None, |
|
credentials_base64=None, |
|
default_query_job_config=None, |
|
location=None, |
|
project_id=None, |
|
): |
|
default_project = None |
|
|
|
if credentials_base64: |
|
credentials_info = json.loads(base64.b64decode(credentials_base64)) |
|
|
|
if credentials_path: |
|
credentials = service_account.Credentials.from_service_account_file( |
|
credentials_path |
|
) |
|
credentials = credentials.with_scopes(SCOPES) |
|
default_project = credentials.project_id |
|
elif credentials_info: |
|
credentials = service_account.Credentials.from_service_account_info( |
|
credentials_info |
|
) |
|
credentials = credentials.with_scopes(SCOPES) |
|
default_project = credentials.project_id |
|
else: |
|
credentials, default_project = google.auth.default(scopes=SCOPES) |
|
|
|
if project_id is None: |
|
project_id = default_project |
|
|
|
return bigquery.Client( |
|
client_info=google_client_info(), |
|
project=project_id, |
|
credentials=credentials, |
|
location=location, |
|
default_query_job_config=default_query_job_config, |
|
) |
Describe the solution you'd like
The create_bigquery_engine method should also accept a user_agent and use that instead of the default sqlalchemy user_agent, if provided.
For now, as a workaround in my code, I'm reimplementing the create_bigquery_engine method myself and setting the client_info directly.
Is your feature request related to a problem? Please describe.
The Google Cloud Ready - BigQuery partnership program requires partners to set a custom UserAgent. This is so Google can correctly attribute usage. However, there is no built in way to set the UserAgent in this library. It's hardcoded to
sqlalchemyright now.python-bigquery-sqlalchemy/sqlalchemy_bigquery/_helpers.py
Lines 27 to 69 in 0b3ab54
Describe the solution you'd like
The
create_bigquery_enginemethod should also accept a user_agent and use that instead of the default sqlalchemy user_agent, if provided.For now, as a workaround in my code, I'm reimplementing the
create_bigquery_enginemethod myself and setting the client_info directly.