cachetools

In-memory memoizing cache collections and decorators for Python, beyond the standard library's lru_cache

Library
PyPI
v7.2.0
2,780 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
71 /100 Good
Development Activity 88
Maintenance 44
Community 52
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 75
Code Quality 78
Innovation 62
Learning Curve 85

cachetools provides various memoizing collections and decorators for Python, including variants of the standard library’s @lru_cache function decorator. A cache in this module is a mutable mapping of a fixed maximum size; when full, the cache discards items based on a chosen cache algorithm (LRU, LFU, TTL, FIFO, RR, and more).

The library exposes both cache classes (LRUCache, TTLCache, etc.) that behave as regular dict-like mappings, and @cached/@cachedmethod decorators that wrap functions or methods to transparently memoize their results against any of those cache instances, including thread-safe usage via an explicit lock argument.

What You Get

  • Cache classes implementing LRU, LFU, TTL, FIFO, RR, and other eviction algorithms as dict-like mutable mappings
  • @cached and @cachedmethod decorators for memoizing plain functions and instance/class methods
  • A keys module for building custom cache keys from function arguments (e.g. ignoring specific parameters)
  • Thread-safe usage support via an explicit lock argument on the decorators
  • A func module offering functools.lru_cache-compatible drop-in decorators backed by cachetools’ cache classes

Common Use Cases

  • Memoizing expensive pure-function calls (recursive algorithms, API lookups) with an LRU or TTL bound
  • Caching per-instance computed properties or expensive method calls via @cachedmethod
  • Rate-limiting external API calls by caching responses for a fixed TTL window
  • Replacing ad-hoc dict-based caches with a maintained, size-bounded, thread-safe alternative

Under The Hood

Architecture - The package is organized as a small src/cachetools module: __init__.py (774 lines) defines the cache classes (Cache, LRUCache, LFUCache, TTLCache, FIFOCache, RRCache, etc.) as subclasses of a shared MutableMapping-based base, _cached.py and _cachedmethod.py implement the decorator logic separately for functions vs. methods, and keys.py provides key-generation helpers used by the decorators. Tech Stack - Pure Python with no runtime dependencies, using only the standard library’s collections.abc and time modules; packaged with a standard pyproject.toml/src-layout build. Code Quality - 14 test modules under tests/ cover the individual cache classes and decorators, CI runs via GitHub Actions with Codecov coverage reporting badges shown in the README, and the codebase is stable/mature (mature project per repo-health signals) with infrequent but steady maintenance. API Design - the cache classes are deliberately dict-like (MutableMapping subclasses), so users already familiar with Python dicts can drop them in directly; the @cached(cache=...) decorator mirrors functools.lru_cache’s ergonomics while accepting any cache instance, keeping the public surface small and consistent across eviction strategies.

Used by 18 apps in this directory

TypeScript
56%
Other

agenta

AI Development · Developer Tools · Devops

4,788

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript 56%
Python 39%
Updated 6 days ago
Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 5 days ago
Python
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 89%
Updated 5 days ago
Python
55%
Other

authentik

Authentication · Security

25,758

The self-hosted Identity Provider that replaces Okta, Auth0, and Entra ID with a unified SSO platform supporting SAML, OAuth2/OIDC, LDAP, RADIUS, and WebAuthn.

View details
92
Repo Health
81
Technical
66
Dependency
Built with
Python 55%
TypeScript 36%
Updated 5 days ago
Python
66%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,596

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python 66%
TypeScript 33%
Updated 5 days ago
Python
82%
Other

fish-speech

AI Development · Developer Tools · Music Audio

32,864

SOTA open-source dual-autoregressive text-to-speech model with rapid voice cloning, inline emotion tags, and real-time streaming inference across 80+ languages.

View details
69
Repo Health
71
Technical
73
Dependency
Built with
Python 82%
TypeScript 14%
Updated 2 weeks ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 2 weeks ago
Python
69%
MIT

Langflow

AI Agents · AI Development

155,319

Build, test, and deploy AI agents and RAG workflows visually with native API and MCP server export.

View details
90
Repo Health
85
Technical
65
Dependency
Built with
Python 69%
TypeScript 22%
Updated 5 days ago
Python
58%
Apache 2.0

MLflow

AI Development · Monitoring

28,154

The open source AI engineering platform for debugging, evaluating, monitoring, and optimizing production LLMs and agents at scale.

View details
97
Repo Health
86
Technical
66
Dependency
Built with
Python 58%
TypeScript 33%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers