skillfed

expiring-dict

Python dict with TTL support for auto-expiring caches

expiring-dict v1.1.2 185.5K downloads/30d#10,009 on PyPI25
Permissive license AGING released

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-dict

uv

uv add expiring-dict

poetry

poetry add expiring-dict

Installing 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

License :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3

Tags

python dict with ttlauto-expiring cachekey expiration dictionarytime-to-live cachetemporary key storagecache with timeoutexpiring dictionary
cachingttlauto-expiring

More Utilities packages