Skip to content

feat(core): implement PEP 0810 explicit lazy imports in google-cloud-core - #18052

Merged
hebaalazzeh merged 1 commit into
mainfrom
feature/lazy-imports-google-cloud-core
Aug 10, 2026
Merged

feat(core): implement PEP 0810 explicit lazy imports in google-cloud-core#18052
hebaalazzeh merged 1 commit into
mainfrom
feature/lazy-imports-google-cloud-core

Conversation

@hebaalazzeh

Copy link
Copy Markdown
Contributor

This PR implements PEP 0810 explicit lazy imports in google-cloud-core.

On Python 3.15+, this defers loading of heavy inner modules and third-party dependencies (grpcio, cryptography, requests, and protobuf descriptor pools) to reduce serverless cold starts and memory footprints.

On Python 3.14 and below, this falls back safely to eager execution with zero backwards-compatibility risk.

Related Links

Design doc: go/sdk:python-lazy-loading

@hebaalazzehhebaalazzeh self-assigned this Aug 10, 2026

@gemini-code-assistgemini-code-assistBot 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 implements PEP 0810 explicit lazy imports (lazy_modules) across several modules in google-cloud-core to optimize cold starts and memory footprints in Python 3.15+. The review feedback correctly identifies that using importlib.util.find_spec on submodules (such as google.auth.api_key) eagerly imports their parent packages, which defeats the purpose of lazy loading. The reviewer suggests using module-level getattr to defer the resolution of HAS_GOOGLE_AUTH_API_KEY until it is actually accessed.

Comment threadpackages/google-cloud-core/google/cloud/client/__init__.py Outdated
Comment threadpackages/google-cloud-core/google/cloud/client/__init__.py Outdated
Comment threadpackages/google-cloud-core/google/cloud/client/__init__.py Outdated
@hebaalazzeh
hebaalazzehforce-pushed the feature/lazy-imports-google-cloud-core branch 3 times, most recently from 88be17b to 8f73f3bCompareAugust 10, 2026 21:18
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review August 10, 2026 21:23
@hebaalazzeh
hebaalazzeh requested a review from a team as a code ownerAugust 10, 2026 21:23
Comment threadpackages/google-cloud-core/google/cloud/_helpers/__init__.py Outdated
Comment threadpackages/google-cloud-core/google/cloud/_helpers/__init__.py
Comment threadpackages/google-cloud-core/google/cloud/_http/__init__.py
Comment threadpackages/google-cloud-core/google/cloud/_helpers/__init__.py Outdated
…core
This PR implements PEP 0810 explicit lazy imports in google-cloud-core.
On Python 3.15+, this defers loading of heavy inner modules and third-party dependencies (grpcio, cryptography, requests, and protobuf descriptor pools) to reduce serverless cold starts and memory footprints.
On Python 3.14 and below, this falls back safely to eager execution with zero backwards-compatibility risk.
### Related Links
- GAPIC Implementation PR: #17591
- google-api-core gapic_v1 PR: #17673
- google-api-core operations_v1 PR: #17724
- google-auth transport PR: #17679
@hebaalazzeh
hebaalazzehforce-pushed the feature/lazy-imports-google-cloud-core branch from 8f73f3b to b7f4f01CompareAugust 10, 2026 21:48
@hebaalazzeh
hebaalazzeh merged commit 5a7ed02 into mainAug 10, 2026
52 checks passed
@hebaalazzeh
hebaalazzeh deleted the feature/lazy-imports-google-cloud-core branch August 10, 2026 22:57
@release-pleaserelease-pleaseBot mentioned this pull request Aug 10, 2026
Sign up for freeto 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.

2 participants

@hebaalazzeh@ohmayr