5X Google BigQuery Client Authentication Library
This Python library provides a simple way to create a Google BigQuery client using either an access token or a service account JSON file. It handles authentication seamlessly, allowing developers to focus on querying BigQuery.
- Preferred Authentication: Access Token (
FIVEX_BIGQUERY_ACCESS_TOKEN) - Fallback Authentication: Service Account JSON (
FIVEX_BIGQUERY_SERVICE_ACCOUNT_KEY)
Installation
Install the package from PyPI using:
pip install 5x-google-bigquery-auth-manager
Environment Variables
This function relies on environment variables for authentication.
| Variable | Description | Example |
|---|---|---|
FIVEX_BIGQUERY_ACCESS_TOKEN |
Access token for authentication | ya29.a0AfH6SMA... |
FIVEX_BIGQUERY_DEFAULT_PROJECT_ID |
Your BigQuery project ID | your-project-id |
FIVEX_BIGQUERY_SERVICE_ACCOUNT_KEY |
Path to the service account JSON key file | /path/to/service_account.json |
Example: Setting Environment Variables
export FIVEX_BIGQUERY_ACCESS_TOKEN="your-access-token"
export FIVEX_BIGQUERY_DEFAULT_PROJECT_ID="your-project-id"
export FIVEX_BIGQUERY_SERVICE_ACCOUNT_KEY="/path/to/service_account.json"
Usage
Import and Use in Python
from bigquery_auth import create_bigquery_client
try:
client = create_bigquery_client()
print("✅ BigQuery Client Created Successfully!")
except Exception as e:
print(f"❌ Error: {e}")
Function Overview
create_bigquery_client()
Creates a BigQuery client using either:
- Access Token (Preferred)
- Service Account JSON File (Fallback)
How It Works
✔ First, tries to authenticate using the access token (FIVEX_BIGQUERY_ACCESS_TOKEN).
✔ If the access token is expired or invalid, it raises an exception.
✔ If no access token is available, it attempts authentication via service account JSON.
✔ Implements logging and error handling for seamless debugging.
Error Handling
This function will raise exceptions in case of failure:
| Exception | Cause |
|---|---|
ValueError |
No authentication method found |
RefreshError |
Access token is expired or invalid |
GoogleAPICallError |
BigQuery API request failure |
BadRequest |
Insufficient permissions to access BigQuery |
Example Handling in Python
try:
client = create_bigquery_client()
except RefreshError as e:
print(f"❌ Token Error: {e}")
except ValueError as e:
print(f"❌ Configuration Error: {e}")
except GoogleAPICallError as e:
print(f"❌ BigQuery API Error: {e}")
except BadRequest as e:
print(f"❌ Permission Error: {e}")
Logging
This function uses Python’s built-in logging module to track:
- Which authentication method is used (Access Token or Service Account)
- Errors and exceptions for easier debugging
Why Use This Library?
✔ Simplifies Google BigQuery authentication – No need to manage authentication manually.
✔ Supports both Access Tokens & Service Account authentication – Provides flexibility.
✔ Ensures proper error handling – Avoids silent failures with meaningful error messages.
✔ Easy to integrate into any project – Just install and use.
Metadata
Release files for 5x-google-bigquery-auth-manager 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| 5x_google_bigquery_auth_manager-0.1.2.tar.gz | 3.9 kB | Without provenance | Details for 5x_google_bigquery_auth_manager-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| 5x_google_bigquery_auth_manager-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for 5x_google_bigquery_auth_manager-0.1.2-py3-none-any.whl |
Total release size: 8.3 kB
Release files / 5x_google_bigquery_auth_manager-0.1.2.tar.gz
| Download URL | 5x_google_bigquery_auth_manager-0.1.2.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f821cd3e706dc4f62fa015715bdca1103fc2b941fd1bbedc276aa733ec666a5
|
|
BLAKE2b-256 checksum How to use checksums |
ab3e2505c75c1dad8e25768b188e9e901c34f1ea1e1a4e3ab30fe6a6363095c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Release files / 5x_google_bigquery_auth_manager-0.1.2-py3-none-any.whl
| Download URL | 5x_google_bigquery_auth_manager-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8944d0915d5586c474d96c14560ecbf05e705e484441806befa6d31fbaf2002d
|
|
BLAKE2b-256 checksum How to use checksums |
bd39c64bff81a2b974160db1652e4fba695125d826169c86ce2051d008fafa31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.9.6
|
Security for 5x-google-bigquery-auth-manager 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.