Skip to content

feat: gapic centralization into api core#17628

Open
hebaalazzeh wants to merge 20 commits into
mainfrom
feat/gapic-centralization-api-core
Open

feat: gapic centralization into api core#17628
hebaalazzeh wants to merge 20 commits into
mainfrom
feat/gapic-centralization-api-core

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Update and Release google-api-core

This PR introduces centralized helper functions into google.api_core.gapic_v1.client_helpers. The goal of this centralization is to reduce package size, improve maintainability, and boost import performance of generated GAPIC clients by moving redundant, service-agnostic boilerplate logic into google-api-core.

Key Changes

  • Centralized GAPIC Helpers: Created google.api_core.gapic_v1.client_helpers containing logic previously repeated across generated clients (e.g., get_default_mtls_endpoint, use_client_cert_effective, get_api_endpoint, and get_universe_domain).
  • Public Method Exposure: Removed the _ prefix from these functions so they can be securely imported and utilized by external generated clients.
  • Backward Compatibility: Added internal aliases (e.g., _use_client_cert_effective = use_client_cert_effective) to prevent breaking changes for existing GAPIC clients (over 2,400+ repos) that have not yet been regenerated.
  • Comprehensive Test Coverage: Added exhaustive unit tests for all helper functions in test_client_helpers.py.
  • CI Environment Hardening:
    • Handled grpc optional dependencies gracefully to ensure tests pass in install_grpc=False environments.
    • Ensured older versions of google-auth (e.g. <=2.14.1) pass in the CI test matrix by safely validating should_use_client_cert availability.

Next Steps (Phase 2)

Once this PR is merged and a new minor version of google-api-core (e.g. 2.18.0) is released, we can update the GAPIC generator to utilize these centralized helpers and stop emitting the redundant logic.

Note

Full details and baseline metrics are available in the attached Design Document.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new client_helpers module in google-api-core containing helper functions for GAPIC client initialization, and adds global lazy imports control (__lazy_modules__) to google-cloud-compute. The review feedback suggests optimizing performance by compiling the mTLS endpoint regular expression at the module level rather than inside the function. Additionally, it recommends correcting the type annotations in get_api_endpoint to use Optional[Any] for client_cert_source and Optional[str] for the return type.

Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py
Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py Outdated
Comment thread packages/google-api-core/google/api_core/gapic_v1/client_helpers.py
@hebaalazzeh hebaalazzeh self-assigned this Jul 6, 2026
@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-centralization-api-core branch from 5e1eb20 to ad1c01f Compare July 6, 2026 21:21
@hebaalazzeh

Copy link
Copy Markdown
Contributor Author

/gemini

@hebaalazzeh hebaalazzeh force-pushed the feat/gapic-centralization-api-core branch from c27695d to 2353e82 Compare July 7, 2026 20:56
@hebaalazzeh hebaalazzeh marked this pull request as ready for review July 7, 2026 21:01
@hebaalazzeh hebaalazzeh requested a review from a team as a code owner July 7, 2026 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant