expiringdict
Dictionary with auto-expiring values for caching purposes
What it is and what it does
ExpiringDict is a Python caching library that wraps a dictionary with automatic value expiration and capacity limits. It stores key-value pairs that are removed either when their time-to-live (max_age_seconds) expires or when the dictionary reaches its maximum size (max_len), at which point the oldest entries are deleted. Expiration is checked on any access to the dictionary, and the object is locked during cleanup to prevent concurrent modification issues.
The package is useful for scenarios where you need a simple, in-memory cache with automatic cleanup. It supports initialization from regular dicts or other ExpiringDict instances, and can be pickled. Note that iteration over the dictionary and the keys() method do not trigger expiration of stale values—only direct access does.
Use it for:
- Caching API responses or database query results with automatic expiration after a set time.
- Rate-limiting or throttling by tracking request counts that decay over time.
- Session storage in web applications where sessions expire after inactivity.
- Temporary storage of computed results that should be refreshed periodically.
- Deduplication of recent events or messages with automatic cleanup.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ExpiringDict is an ordered dictionary that automatically removes values after a specified time interval, with a fixed capacity limit, designed for caching purposes.
Yes, if you need a simple, lightweight in-memory cache with automatic expiration and can tolerate the abandoned status. The library is stable and has no known vulnerabilities, but you should not expect bug fixes or new features. Consider alternatives if you need active maintenance, thread-safety guarantees beyond basic locking, or support for newer Python versions.
Install
expiringdict on PyPI
pip
pip install expiringdictuv
uv add expiringdictpoetry
poetry add expiringdictInstalling expiringdict
Before you install
Installation is straightforward with no compiled dependencies. However, the package is abandoned—last release was 1515 days ago with no recent maintenance activity, so expect no bug fixes or updates.
License in practice
Licensed under Apache 2 (permissive), so you can use it freely in commercial and open-source projects without restrictive obligations.
Quickstart
pip install expiringdict
from expiringdict import ExpiringDict
cache = ExpiringDict(max_len=100, max_age_seconds=10)
cache["key"] = "value"
print(cache.get("key"))
Verify before relying
- Thread-safety guarantees during concurrent access beyond the stated locking during cleanup.
- Performance characteristics with large capacity or high expiration rates.
- Compatibility with Python versions beyond 3.6 given the abandoned status.
Package facts
| License | Apache 2 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing |
| Maintenance | abandoned — 1,515 days since the last release |
| First released | |
| Downloads | 10,875,172/month — #1,429 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: expiringdict-1.2.2-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
circular-dictCircularDict is a Python dictionary that…
permissive · top 5,000 on PyPI
expiring-dictExpiringDict is a Python dictionary that…
permissive · top 15,000 on PyPI
cacheoutCacheout provides in-memory caching with…
permissive · top 5,000 on PyPI
cache-to-diskA decorator that caches function results to…
permissive · top 15,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
onecacheOneCache provides LRU-based caching decorators…
permissive · top 15,000 on PyPI
requests-cacheAdds persistent HTTP caching to the requests…
permissive · top 5,000 on PyPI
cachierCachier is a decorator that adds persistent,…
permissive · top 15,000 on PyPI
django-session-timeoutAdds automatic session expiration to Django…
permissive · top 15,000 on PyPI