CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-airbyte-source-google-directory

Airbyte source connector for Google Directory (Google Workspace Admin Directory API) that extracts users, groups, and group memberships.

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

client-operations.mddocs/

Client Operations

High-level client interface for managing Google Directory API interactions. The Client class provides authentication management, health checks, stream configuration, and orchestrates access to individual API endpoints.

Capabilities

Client Initialization

The main client class that handles Google Directory API interactions through the Airbyte CDK framework.

class Client(BaseClient):
    """
    Main client class handling Google Directory API interactions.
    
    Extends Airbyte CDK BaseClient to provide Google Directory-specific
    functionality including authentication, health checks, and stream management.
    """
    
    def __init__(self, credentials: Mapping[str, Any] = None, credentials_json: str = None, email: str = None):
        """
        Initialize the Google Directory client.
        
        Parameters:
        - credentials: Dict containing authentication credentials
        - credentials_json: JSON string of service account credentials (legacy)
        - email: Admin email for service account delegation (legacy)
        
        The constructor supports both new (credentials dict) and legacy
        (credentials_json + email) configuration formats.
        """

Health Check Operations

Verify connectivity and authentication with the Google Directory API.

def health_check(self) -> Tuple[bool, str]:
    """
    Perform health check against Google Directory API.
    
    Tests connectivity by attempting to fetch users from the directory.
    
    Returns:
    - Tuple[bool, str]: (is_healthy, error_message)
        - is_healthy: True if connection successful, False otherwise  
        - error_message: None if healthy, error description if unhealthy
    """

Stream Management

Access configured streams with Airbyte-specific metadata and primary key configuration.

@property
def streams(self) -> Generator[AirbyteStream, None, None]:
    """
    Generator yielding AirbyteStream objects with primary keys configured.
    
    All streams are configured with source_defined_primary_key = [["id"]]
    to use the 'id' field as the primary key for change detection.
    
    Yields:
    - AirbyteStream objects for users, groups, and group_members streams
    """

Stream Method Enumeration

Internal method for mapping stream names to their corresponding API list methods.

def _enumerate_methods(self) -> Mapping[str, callable]:
    """
    Enumerate available stream methods for the Airbyte CDK.
    
    Maps stream names to their corresponding API list methods from
    the configured stream APIs (users, groups, group_members).
    
    Returns:
    - Mapping[str, callable]: Dictionary mapping stream names to list methods
    """

State Management

Stream state management for incremental synchronization (not implemented in current version).

def get_stream_state(self, name: str) -> Any:
    """
    Get stream state for incremental synchronization.
    
    Parameters:
    - name: Stream name
    
    Returns:
    - Any: Stream state (currently not implemented)
    """

def set_stream_state(self, name: str, state: Any):
    """
    Set stream state for incremental synchronization.
    
    Parameters:
    - name: Stream name
    - state: State to persist
    
    Currently not implemented - state management is handled by Airbyte platform.
    """

Usage Examples

Basic Client Setup with OAuth

from source_google_directory.client import Client

# OAuth credentials configuration
oauth_credentials = {
    "client_id": "your-oauth-client-id",
    "client_secret": "your-oauth-client-secret",
    "refresh_token": "your-refresh-token"
}

# Initialize client
client = Client(credentials=oauth_credentials)

# Perform health check
is_healthy, error_msg = client.health_check()
if is_healthy:
    print("Connection successful!")
else:
    print(f"Connection failed: {error_msg}")

Basic Client Setup with Service Account

from source_google_directory.client import Client

# Service account credentials
service_credentials = {
    "credentials_json": '{"type": "service_account", "project_id": "...", ...}',
    "email": "admin@yourdomain.com"
}

# Initialize client
client = Client(credentials=service_credentials)

# Check connection health
is_healthy, error_msg = client.health_check()

Legacy Configuration Format

# Legacy format (still supported)
client = Client(
    credentials_json='{"type": "service_account", ...}',
    email="admin@yourdomain.com"
)

Stream Access

# Get available streams
for stream in client.streams:
    print(f"Stream: {stream.name}")
    print(f"Primary key: {stream.source_defined_primary_key}")

Authentication Support

The client supports two Google authentication methods:

OAuth 2.0 (Web Server Application)

  • Requires: client_id, client_secret, refresh_token
  • Use case: Interactive authentication scenarios
  • Scopes: Directory read-only permissions

Service Account

  • Requires: credentials_json, email (admin email for delegation)
  • Use case: Server-to-server authentication
  • Setup: Requires domain-wide delegation configuration

Internal Architecture

The Client class orchestrates several components:

  • API instance: Core Google Directory API wrapper
  • Stream APIs: Individual API handlers (UsersAPI, GroupsAPI, GroupMembersAPI)
  • Method enumeration: Maps stream names to corresponding API list methods
  • Primary key configuration: Sets consistent primary keys across all streams

Install with Tessl CLI

npx tessl i tessl/pypi-airbyte-source-google-directory

docs

client-operations.md

google-directory-apis.md

index.md

main-connector.md

tile.json