Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Googleapis Python genai Common Utilities

From Leeroopedia
Revision as of 12:48, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Googleapis_Python_genai_Common_Utilities.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains SDK_Infrastructure, Utilities
Last Updated 2026-02-15 14:00 GMT

Overview

Concrete tool for shared utility functions, base classes, and data manipulation helpers used across the Google Gen AI SDK.

Description

The _common module provides foundational infrastructure including the SDK-level BaseModel (Pydantic-based with camelCase aliasing), CaseInSensitiveEnum, path-based dictionary manipulation (set_value_by_path, get_value_by_path, move_value_by_path), pretty-printing utilities, the experimental_warning decorator, and recursive dict update helpers. It underpins all public API modules.

Usage

This module is imported internally by other SDK modules. Users typically interact with its BaseModel indirectly through SDK types.

Code Reference

Source Location

Signature

class BaseModel(pydantic.BaseModel):
    """SDK-level Pydantic BaseModel with camelCase aliasing and base64 byte encoding."""
    def to_json_dict(cls, data: dict) -> dict: ...

class CaseInSensitiveEnum(enum.Enum):
    """Enum supporting case-insensitive member lookup with unknown value warnings."""

def set_value_by_path(data: Optional[dict], keys: list[str], value: Any) -> None: ...
def get_value_by_path(data: Any, keys: list[str], *, default_value: Any = None) -> Any: ...
def move_value_by_path(data: Any, paths: dict[str, str]) -> None: ...
def convert_to_dict(obj: object, convert_keys: bool = False) -> Any: ...
def encode_unserializable_types(data: dict[str, object]) -> dict[str, object]: ...
def experimental_warning(message: str) -> Callable: ...
def recursive_dict_update(target_dict: StringDict, update_dict: StringDict) -> None: ...
def is_duck_type_of(obj: Any, cls: type[pydantic.BaseModel]) -> bool: ...

Import

from google.genai import _common

I/O Contract

Inputs

Name Type Required Description
data dict Varies Dictionary to manipulate via path-based operations
keys list[str] For path ops Dot-separated path components, supports array notation
obj Any For convert_to_dict Object to recursively convert to dict

Outputs

Name Type Description
get_value_by_path returns Any Value at the specified nested path
convert_to_dict returns dict Recursive dict representation of any object
encode_unserializable_types returns dict Dict with bytes/datetime encoded as JSON-safe values

Usage Examples

from google.genai._common import set_value_by_path, get_value_by_path

# Manipulate nested dictionaries by path
data = {}
set_value_by_path(data, ["model", "config", "temperature"], 0.7)
# data = {"model": {"config": {"temperature": 0.7}}}

value = get_value_by_path(data, ["model", "config", "temperature"])
# value = 0.7

Related Pages

Page Connections

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