PyData Google Auth is a Python package that provides helper functions for authenticating to Google APIs, simplifying the process of obtaining and caching user and service account credentials. It wraps the underlying `google-auth` and `google-auth-oauthlib` libraries to offer a more convenient interface. The current version is 1.9.1, and the library maintains an active release cadence with frequent minor and patch updates.
pip install pydata-google-authVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to obtain user credentials using `get_user_credentials` and then use them to initialize a Google Cloud BigQuery client. The process will typically open a browser window for you to authenticate via Google's OAuth 2.0 flow if credentials are not already cached.
Ensure your environment allows for a local web server (ports 8080-8089 by default) for the OAuth callback, or explicitly set `use_local_webserver=False` and be prepared for the console-based flow, which may eventually cease to function. The `auth_local_webserver` parameter is also deprecated; use `use_local_webserver` instead.
Upgrade your Python environment to 3.9 or newer. Python 3.13 is now officially supported.
Obtain your own OAuth 2.0 Client ID and secret from the Google Cloud Console and pass them to the `client_id` and `client_secret` parameters of `get_user_credentials`.
Store the service account key in a secure location and reference its path via an environment variable (e.g., `GOOGLE_APPLICATION_CREDENTIALS`) or load it from a secure secret manager. Avoid hardcoding paths or embedding keys directly in code.
To prevent credentials from being written to disk, pass `credentials_cache=pydata_google_auth.cache.NOOP` to `get_user_credentials` or `default`.
Install the specific `google.cloud` package you intend to use (e.g., `pip install google-cloud-bigquery`).
Install the required Google Cloud client libraries (e.g., `pip install google-cloud-bigquery`) into your environment.
Install the package using pip: `pip install pydata-google-auth` or conda: `conda install pydata-google-auth --channel conda-forge`.
Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to the path of your service account key file (e.g., `export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"`), or run `gcloud auth application-default login` to set up user application default credentials locally.
Ensure that a `client_secrets.json` file is correctly configured and accessible if using `get_user_credentials`, or that the environment variables for Application Default Credentials are set. Verify that the necessary API scopes are correctly provided and enabled for your Google Cloud project.
Ensure that when obtaining or loading user credentials, all necessary fields including `refresh_token`, `token_uri`, `client_id`, and `client_secret` are present in the `google.oauth2.credentials.Credentials` object. Re-run the full OAuth 2.0 authorization flow to acquire a complete set of credentials including a refresh token if these fields are missing.
Check your internet connection, verify proxy settings if applicable, inspect firewall rules to ensure outbound connections to Google's authentication endpoints (e.g., `accounts.google.com`) are allowed, and consider implementing retry logic for transient network failures.