expiring-dict
Python dict with TTL support for auto-expiring caches
What it is and what it does
ExpiringDict wraps Python's built-in dict to add automatic key expiration based on a time-to-live (TTL) value. You can set a default TTL at the class level so all keys expire after that duration, or assign individual TTLs to specific keys using the ttl() method for fine-grained control. Keys that have exceeded their TTL are no longer accessible via membership tests or lookups.
The package depends on sortedcontainers to manage the expiration timeline efficiently. It's designed for caching scenarios where you want temporary storage without manual cleanup—common in session management, rate-limiting, or transient data buffering. The aging maintenance status and lack of a documented Python version requirement suggest it's a stable but minimal project.
Use it for:
- Session storage that automatically clears old sessions after a timeout period
- Rate-limiting buckets that reset after a fixed time window
- Temporary cache for API responses that should refresh after a TTL
- In-memory job queues where tasks expire if not processed within a deadline
- Transient request deduplication that forgets duplicate keys after a time window
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
ExpiringDict is a Python dictionary that automatically removes keys after a specified time-to-live (TTL) expires, supporting both class-level and per-key TTL configuration for building auto-expiring caches.
Yes, if you need a lightweight, zero-configuration TTL dictionary for simple caching. The low install friction, permissive license, and recent maintenance make it a safe choice for projects that don't require advanced cache features. However, verify thread-safety and expiration semantics for your specific use case before relying on it in production.
Install
expiring-dict on PyPI
pip
pip install expiring-dictuv
uv add expiring-dictpoetry
poetry add expiring-dictInstalling expiring-dict
Before you install
Low install friction: pure Python wheel with a single runtime dependency (sortedcontainers). Last commit was recent (2025-02-28) and the repository is active, though the project is aging with no documented Python version requirement.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely with minimal restrictions, making it suitable for both open-source and commercial projects.
Quickstart
pip install expiring-dict
from expiring_dict import ExpiringDict
from time import sleep
cache = ExpiringDict(1) # 1-second TTL
cache["key"] = "value"
assert "key" in cache
sleep(1)
assert "key" not in cache # Expired
Verify before relying
- Whether expired keys are removed on access, on a background timer, or both
- Memory overhead and performance characteristics with large numbers of keys
- Thread-safety guarantees for concurrent access
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — sortedcontainers |
| Maintenance | aging — 532 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 185,521/month — #10,009 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: expiring_dict-1.1.2-py3-none-any.whl
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
expiringdictExpiringDict is an ordered dictionary that…
permissive · top 5,000 on PyPI
cacheoutCacheout provides in-memory caching with…
permissive · top 5,000 on PyPI
cachettlcachettl provides LRU TTL cache decorators for…
permissive · top 15,000 on PyPI
onecacheOneCache provides LRU-based caching decorators…
permissive · top 15,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
django-session-timeoutAdds automatic session expiration to Django…
permissive · top 15,000 on PyPI
async-lruAn LRU cache decorator for async functions that…
permissive · top 1,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
cache-to-diskA decorator that caches function results to…
permissive · top 15,000 on PyPI
pyarmorPyarmor obfuscates Python scripts to protect…
unclear · top 15,000 on PyPI