Implementation:Googleapis Python genai Interactions Transform
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Data_Transformation, SDK_Infrastructure |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete tool for type-based dictionary transformation with field aliasing and format handling for API serialization.
Description
The _transform module provides transform and async_transform functions that convert Python-style typed dictionaries into the JSON structure expected by the API. It handles PropertyInfo annotations for field aliasing, date/base64 formatting, and recursive type traversal.
Usage
Internal infrastructure used by the _interactions request pipeline to serialize typed parameters into API-compatible JSON.
Code Reference
Source Location
- Repository: Googleapis_Python_genai
- File: google/genai/_interactions/_utils/_transform.py
- Lines: 1-472
Signature
class PropertyInfo:
alias: str | None
format: PropertyFormat | None
format_template: str | None
discriminator: str | None
def transform(data: _T, expected_type: object) -> _T: ...
def maybe_transform(data: object, expected_type: object) -> Any | None: ...
async def async_transform(data: _T, expected_type: object) -> _T: ...
async def async_maybe_transform(data: object, expected_type: object) -> Any | None: ...
Import
from google.genai._interactions._utils._transform import transform, PropertyInfo
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| data | _T | Yes | Python dict or typed dict to transform |
| expected_type | type | Yes | Type annotation defining field mappings |
Outputs
| Name | Type | Description |
|---|---|---|
| transform returns | _T | Transformed dict with API-compatible keys and formats |
Usage Examples
# Internal usage pattern
from google.genai._interactions._utils._transform import transform
# Transform a TypedDict with field aliases
result = transform(
{"model_name": "gemini-2.0-flash", "max_tokens": 100},
ExpectedParamType, # TypedDict with PropertyInfo annotations
)
# result = {"modelName": "gemini-2.0-flash", "maxTokens": 100}
Related Pages
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment