Skip to content

perf: lazily import the interactions API to speed up import google.genai#2701

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
copybara/945816846
Open

perf: lazily import the interactions API to speed up import google.genai#2701
copybara-service[bot] wants to merge 1 commit into
mainfrom
copybara/945816846

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Jul 10, 2026

Copy link
Copy Markdown

perf: lazily import the interactions API to speed up import google.genai

The top-level package eagerly imported the interactions submodule, and
client.py eagerly imported the _gaos backend, so every import google.genai paid for hundreds of interactions-API modules even when the
caller only uses generate_content.

Defer both: make interactions a lazy module attribute via getattr,
and move the _gaos imports in client.py under TYPE_CHECKING plus into the
Client/AsyncClient properties that construct them. from __future__ import annotations keeps the property return annotations valid without the eager
import. The _gaos modules now load only when .interactions/.agents/
.webhooks (or the nextgen client) are first accessed.

@copybara-service copybara-service Bot force-pushed the copybara/945816846 branch from 897f775 to 3ce65ff Compare July 10, 2026 19:03
@copybara-service copybara-service Bot changed the title No public description perf: lazily import the interactions API to speed up import google.genai Jul 10, 2026
@copybara-service copybara-service Bot force-pushed the copybara/945816846 branch 3 times, most recently from 5a2b01a to b8df375 Compare July 10, 2026 21:17
The top-level package eagerly imported the interactions submodule, and
client.py eagerly imported the _gaos backend, so every `import
google.genai` paid for hundreds of interactions-API modules even when the
caller only uses generate_content.

Defer both: make `interactions` a lazy module attribute via __getattr__,
and move the _gaos imports in client.py under TYPE_CHECKING plus into the
Client/AsyncClient properties that construct them. `from __future__ import
annotations` keeps the property return annotations valid without the eager
import. The _gaos modules now load only when .interactions/.agents/
.webhooks (or the nextgen client) are first accessed.

PiperOrigin-RevId: 945816846
@copybara-service copybara-service Bot force-pushed the copybara/945816846 branch from b8df375 to 1e2fe4a Compare July 10, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant