Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

feat(storage): add async credential wrapper#1659

Merged
googlyrahman merged 2 commits intogoogleapis:asyncgoogleapis/python-storage:asyncfrom
googlyrahman:dev-final-2googlyrahman/python-storage:dev-final-2Copy head branch name to clipboard
Dec 19, 2025
Merged

feat(storage): add async credential wrapper#1659
googlyrahman merged 2 commits intogoogleapis:asyncgoogleapis/python-storage:asyncfrom
googlyrahman:dev-final-2googlyrahman/python-storage:dev-final-2Copy head branch name to clipboard

Conversation

@googlyrahman
Copy link

Adds async credential wrapper for async client.

Context:

  • The standard google auth credentials are currently synchronous, and it's asynchronous credentials classes are either not available or marked private.
  • Credential retrieval and refreshing will remain synchronous under the hood. Rationale: As authentication tokens typically possess an expiration lifetime of one hour, the blocking time required for token fetching occurs infrequently. The performance impact of blocking (or utilizing a separate thread for offloading) once per hour is deemed negligible when weighed against the considerable engineering cost of developing and maintaining a asynchronous authentication.

@product-auto-label product-auto-label bot added size: s Pull request size is small. api: storage Issues related to the googleapis/python-storage API. labels Dec 9, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @googlyrahman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a practical solution for integrating existing synchronous Google Auth credentials into asynchronous Python applications. By wrapping the synchronous credentials with an AsyncCredsWrapper, it enables asynchronous clients to utilize these credentials without blocking the event loop during infrequent operations like token refreshes. The approach balances the need for asynchronous compatibility with the engineering cost, focusing on efficiency for operations that are not performance-critical.

Highlights

  • New Async Credential Wrapper: Introduces a new AsyncCredsWrapper class designed to adapt synchronous Google Auth credentials for use in asynchronous contexts.
  • Asynchronous Interface for Synchronous Credentials: The wrapper provides async def refresh and async def before_request methods, allowing synchronous credential operations to be awaited without blocking the main event loop.
  • Thread Pool for Blocking Operations: Blocking operations, such as token refreshes and initial credential application, are offloaded to a separate thread using asyncio.loop.run_in_executor.
  • Performance Rationale: The design acknowledges that credential refreshing is infrequent (typically hourly), making the performance impact of offloading these blocking calls to a thread pool negligible compared to the complexity of a fully asynchronous authentication implementation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@googlyrahman googlyrahman added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 9, 2025
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 9, 2025
Copy link
Contributor

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

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 an AsyncCredsWrapper to adapt synchronous Google Auth credentials for asynchronous use. The approach of using run_in_executor for blocking calls is sound. My review includes a few suggestions to improve the implementation:

  • The __init__ method should be updated to call super().__init__() and use the modern asyncio.get_running_loop() instead of the deprecated get_event_loop().
  • The wrapper should delegate property access (e.g., valid, token) to the wrapped credentials object to ensure it behaves as a transparent proxy and provides correct state information.
  • A minor simplification in the before_request method is also suggested.

These changes will make the wrapper more robust, correct, and easier to use.

google/cloud/storage/_experimental/asyncio/async_creds.py Outdated Show resolved Hide resolved
google/cloud/storage/_experimental/asyncio/async_creds.py Outdated Show resolved Hide resolved
google/cloud/storage/_experimental/asyncio/async_creds.py Outdated Show resolved Hide resolved
@googlyrahman googlyrahman force-pushed the dev-final-2 branch 2 times, most recently from b414a10 to 36e73ba Compare December 9, 2025 18:56
@googlyrahman googlyrahman marked this pull request as ready for review December 9, 2025 18:58
@googlyrahman googlyrahman requested review from a team as code owners December 9, 2025 18:58
return self.creds.valid

async def before_request(self, _request, method, url, headers):
"""Performs credential-specific before request logic."""
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: sentence's meaning is not coming out clearly.

@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Dec 11, 2025
@googlyrahman googlyrahman requested a review from a team as a code owner December 19, 2025 11:08
@googlyrahman googlyrahman merged commit b992294 into googleapis:async Dec 19, 2025
6 checks passed
googlyrahman added a commit to googlyrahman/python-storage that referenced this pull request Feb 5, 2026
Adds async credential wrapper for async client. 

Context:

- The standard google auth credentials are currently synchronous, and
it's asynchronous credentials classes are either not available or marked
private.
- Credential retrieval and refreshing will remain synchronous under the
hood. Rationale: As authentication tokens typically possess an
expiration lifetime of one hour, the blocking time required for token
fetching occurs infrequently. The performance impact of blocking (or
utilizing a separate thread for offloading) once per hour is deemed
negligible when weighed against the considerable engineering cost of
developing and maintaining a asynchronous authentication.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the googleapis/python-storage API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments

Close sidebar
Morty Proxy This is a proxified and sanitized view of the page, visit original site.