Python package Expiring Dict is not working (automatic expiring)

Using the following package for expiring dictionaries doesn’t work. Is there any known deprecation on the package? The GitHub repository seems inactive but the latest release was 1 and half years ago.

If the package is indeed deprecated, is there a well-known replacement?

Python 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from expiring_dict                          import ExpiringDict
>>> denms = ExpiringDict(max_age_seconds=3)
>>> denms["john"] = "doe"
>>> import time
>>> time.sleep(10)
>>> print(list(denms.items()))
[('max_age_seconds', 3), ('john', 'doe')]

From the package’s PyPI page:

Note: Iteration over dict and also keys() do not remove expired values!

IOW, I think you’d find that denms["john"] would not return a value:

>>> import expiringdict
>>> d = expiringdict.ExpiringDict(max_age_seconds=1, max_len=100)
>>> d["foo"] = "bar"
...
>>> d["foo"]
KeyError: 'foo'
>>>

Or, for the other similarly named package:

>>> import expiring_dict
>>> d = expiring_dict.ExpiringDict(1)
>>> d["foo"] = 10
>>> d["foo"]
KeyError: 'foo'
>>>

Leave a Comment