Install & Compatibility
Where this runs
tested against v0.0.18 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 89.5MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 10.6s · import 0.000s · 88MB
89MB installed
● package 89MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
build_oauth_session
✓ from googleauthentication.oauth_session import build_oauth_session
✗ from googleauthentication import build_oauth_session
Functions are located in the `oauth_session` submodule, not directly under the top-level package.
build_oauth_service
✓ from googleauthentication.oauth_session import build_oauth_service
✗ from googleauthentication import build_oauth_service
Functions are located in the `oauth_session` submodule, not directly under the top-level package.
OAuthSession
✓ from googleauthentication.oauth_session import OAuthSession
✗ from googleauthentication import OAuthSession
Classes are located in the `oauth_session` submodule, not directly under the top-level package.
This quickstart demonstrates how to use `build_oauth_service` to obtain an authenticated Google API client (e.g., Google Drive). It requires a `client_secrets.json` file (downloaded from the Google Cloud Console for your project) and specifies the necessary OAuth scopes. The example will prompt for browser-based authentication if no valid token is found, then list up to 5 files from your Google Drive. Remember to replace placeholder `YOUR_CLIENT_ID` and `YOUR_CLIENT_SECRET` with actual environment variables or ensure your `client_secrets.json` is correctly configured.
import os
import json
from googleauthentication.oauth_session import build_oauth_service
# --- Create a dummy client_secrets.json for this example ---
# In a real scenario, this file is downloaded from Google Cloud Console.
# DO NOT hardcode secrets in production code.
client_secrets_path = "client_secrets.json"
dummy_client_secrets_content = {
"web": {
"client_id": os.environ.get("GOOGLE_CLIENT_ID", "YOUR_CLIENT_ID"),
"project_id": "registry-test-project",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": os.environ.get("GOOGLE_CLIENT_SECRET", "YOUR_CLIENT_SECRET"),
"redirect_uris": [
"http://localhost:8080/",
"http://localhost"
]
}
}
with open(client_secrets_path, "w") as f:
json.dump(dummy_client_secrets_content, f)
# ---------------------------------------------------------
SCOPES = ['https://www.googleapis.com/auth/drive.metadata.readonly']
TOKEN_FILE = 'token.json'
try:
# Build an authenticated Google Drive service
print("Attempting to build Google Drive service...")
drive_service = build_oauth_service(
api_name='drive',
api_version='v3',
client_secrets_json=client_secrets_path,
scopes=SCOPES,
token_file=TOKEN_FILE
)
print("Service built successfully.")
# Example: List up to 5 files
print("Fetching files...")
results = drive_service.files().list(
pageSize=5, fields="nextPageToken, files(id, name)").execute()
items = results.get('files', [])
if not items:
print("No files found in your Google Drive.")
else:
print("Files:")
for item in items:
print(f" {item['name']} ({item['id']})")
except Exception as e:
print(f"An error occurred during authentication or API call: {e}")
finally:
# Clean up dummy files created for the example
if os.path.exists(client_secrets_path):
os.remove(client_secrets_path)
if os.path.exists(TOKEN_FILE):
os.remove(TOKEN_FILE)
print("Cleanup complete.")
Upgrade
Version history
0.0.18latest on PyPI · released Oct 9, 2024
Audit
Dependencies
google-authrequiredCore library for Google API authentication.
google-auth-oauthlibrequiredProvides OAuth 2.0 support for Installed Applications and Web Server Applications.
google-api-python-clientrequiredClient library for Google's discovery-based APIs.
google-auth-httplib2requiredAdapter for google-auth to use httplib2.
oauth2clientrequiredLegacy OAuth 2.0 client library; note this library is largely superseded by google-auth for new development.