google-auth-library-python icon indicating copy to clipboard operation
google-auth-library-python copied to clipboard

feat: drop `cachetools` dependency in favor of simple local implementation

Open akx opened this issue 1 year ago • 7 comments

This PR drops the dependency on cachetools, which was only used for its LRU cache class, in favor of a simple local implementation.

This should have a small but positive effect on many downstream users given how many times this library is downloaded per day.

akx avatar Aug 26 '24 11:08 akx

Thank you @akx. Is using the standard library a reasonable alternative? https://docs.python.org/3/library/functools.html#functools.lru_cache

clundin25 avatar Sep 03 '24 15:09 clundin25

@clundin25 Unfortunately not. The transparency of a lru_cached function is not really compatible with how the client code here is e. g. doing if foo in cache:.

akx avatar Sep 03 '24 15:09 akx

@clundin25 Is there anything I can do to help this move along?

akx avatar Sep 11 '24 09:09 akx

How big is the change to update the client code so it can use the standard library and avoid maintaining this implementation?

/cc @sai-sunder-s

westarle avatar Sep 16 '24 11:09 westarle

How big is the change to update the client code so it can use the standard library and avoid maintaining this implementation?

Sorry, I wasn't sure whether that was directed at me or the person cc'd.

Not trivial, since it depends on being able to introspect the cache entry before deciding whether it's usable. lru_cache does not expose such a mechanism (nor being able to replace a single key from the cache, which is also required).

token, expiry = self._cache.get(audience, (None, None))
if token is None or expiry < _helpers.utcnow():

akx avatar Oct 07 '24 10:10 akx

Rebased. Is there anything I can do to help this move along? cc @westarle, @clundin25.

akx avatar Jan 10 '25 06:01 akx

Rebased again. Could this be moved along?

akx avatar Mar 06 '25 11:03 akx

It starts to be more useful now, as there is new major update of cachetools 6.0.0 and it's not possible to use it together with current google-auth.

zladovan avatar May 26 '25 08:05 zladovan

Rebased. Anything I can do to move this along (cc e.g. @clundin25)?

akx avatar Jun 23 '25 13:06 akx

Rebased (post #1773 merge).

akx avatar Aug 20 '25 07:08 akx

Would be great to get this is as indeed it's blocking other projects from updating cachetools beyond 6.0.0

SchubmannM avatar Sep 02 '25 13:09 SchubmannM