Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Environment:Explodinggradients Ragas Google Drive Backend Environment

From Leeroopedia


Knowledge Sources
Domains Infrastructure, Storage
Last Updated 2026-02-10 12:00 GMT

Overview

Google Drive backend environment requiring Google API client libraries and OAuth/service account credentials for storing Ragas datasets and experiments as Google Sheets.

Description

The Google Drive backend (`GDriveBackend`) stores Ragas datasets and experiments as Google Sheets in a user-specified Google Drive folder. It requires the Google API Python client libraries for Sheets and Drive API access, plus either OAuth 2.0 user credentials or a service account JSON file for authentication. The backend converts `DataTable` objects to spreadsheet rows and supports append operations.

Usage

Use this environment when you need to persist datasets and experiment results to Google Drive for sharing or collaboration. It is an optional backend -- the default backends (local CSV, local JSONL, in-memory) require no additional setup. Enable by installing `pip install "ragas[gdrive]"` and configuring credentials.

System Requirements

Category Requirement Notes
Network Outbound HTTPS to Google APIs `sheets.googleapis.com` and `drive.googleapis.com`
Python >= 3.9 Base Ragas requirement
Google Cloud Google Cloud project with Sheets API and Drive API enabled Required for OAuth credentials

Dependencies

Python Packages

  • `google-api-python-client` >= 2.178.0
  • `google-auth` >= 2.40.3
  • `google-auth-oauthlib` >= 1.2.2

Credentials

The following environment variables configure Google Drive authentication:

  • `GDRIVE_CREDENTIALS_PATH`: Path to the Google OAuth `credentials.json` file downloaded from Google Cloud Console.
  • `GDRIVE_SERVICE_ACCOUNT_PATH`: Path to a Google service account JSON key file. Use this for headless/CI environments.
  • `GDRIVE_TOKEN_PATH`: Path to store/read the OAuth token after user authentication. Default: `"token.json"`.

Authentication flow: If `GDRIVE_SERVICE_ACCOUNT_PATH` is set, service account auth is used (no user interaction needed). Otherwise, OAuth 2.0 user flow is triggered using `GDRIVE_CREDENTIALS_PATH`, which opens a browser for consent.

Quick Install

# Install with Google Drive support
pip install "ragas[gdrive]"

# Or install dependencies directly
pip install google-api-python-client>=2.178.0 google-auth>=2.40.3 google-auth-oauthlib>=1.2.2

Code Evidence

Dependency check from `src/ragas/backends/gdrive_backend.py:10-31`:

try:
    from google.oauth2.credentials import Credentials
    from google.oauth2.service_account import Credentials as ServiceAccountCredentials
    from google_auth_oauthlib.flow import InstalledAppFlow
    from googleapiclient.discovery import build

    GDRIVE_AVAILABLE = True
except ImportError:
    GDRIVE_AVAILABLE = False

Credential environment variables from `src/ragas/backends/gdrive_backend.py:100-104`:

GDRIVE_CREDENTIALS_PATH = os.environ.get("GDRIVE_CREDENTIALS_PATH")
GDRIVE_SERVICE_ACCOUNT_PATH = os.environ.get("GDRIVE_SERVICE_ACCOUNT_PATH")
GDRIVE_TOKEN_PATH = os.environ.get("GDRIVE_TOKEN_PATH", "token.json")

Availability guard from `src/ragas/backends/gdrive_backend.py:91-95`:

if not GDRIVE_AVAILABLE:
    raise ImportError(
        "Google Drive dependencies not found. "
        "Install them with: pip install 'ragas[gdrive]'"
    )

Common Errors

Error Message Cause Solution
`ImportError: Google Drive dependencies not found` Missing google-api packages `pip install "ragas[gdrive]"`
`FileNotFoundError: credentials.json` `GDRIVE_CREDENTIALS_PATH` not set or file missing Download credentials from Google Cloud Console and set env var
`google.auth.exceptions.RefreshError` Expired or revoked OAuth token Delete `token.json` and re-authenticate

Compatibility Notes

  • CI/CD Environments: Use service account authentication (`GDRIVE_SERVICE_ACCOUNT_PATH`) since OAuth flow requires a browser.
  • Permissions: The Google Cloud project must have the Google Sheets API and Google Drive API enabled.
  • Scopes: The backend requests full Drive and Sheets access scopes for read/write operations.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment