Extensible memoizing collections and decorators
Project Links
Meta
Author: Thomas Kemmer
Maintainer: Thomas Kemmer
Requires Python: >=3.10
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
Operating System
- OS Independent
Programming Language
- Python
- Python :: 3
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.14
Topic
- Software Development :: Libraries :: Python Modules
This module provides various memoizing collections and decorators, including variants of the Python Standard Library’s @lru_cache function decorator.
from cachetools import cached, LRUCache, TTLCache
# speed up calculating Fibonacci numbers with dynamic programming
@cached(cache={})
def fib(n):
return n if n < 2 else fib(n - 1) + fib(n - 2)
# cache least recently used Python Enhancement Proposals
@cached(cache=LRUCache(maxsize=32))
def get_pep(num):
url = 'http://www.python.org/dev/peps/pep-%04d/' % num
with urllib.request.urlopen(url) as s:
return s.read()
# cache weather data for no longer than ten minutes
@cached(cache=TTLCache(maxsize=1024, ttl=600))
def get_weather(place):
return owm.weather_at_place(place).get_weather()
For the purpose of this module, a cache is a mutable mapping of a fixed maximum size. When the cache is full, i.e. by adding another item the cache would exceed its maximum size, the cache must choose which item(s) to discard based on a suitable cache algorithm.
This module provides multiple cache classes based on different cache algorithms, as well as decorators for easily memoizing function and method calls.
Installation
cachetools is available from PyPI and can be installed by running:
pip install cachetools
Project Resources
License
Copyright (c) 2014-2026 Thomas Kemmer.
Licensed under the MIT License.
7.1.3
May 18, 2026
7.1.2
May 16, 2026
7.1.1
May 03, 2026
7.1.0
May 01, 2026
7.0.6
Apr 20, 2026
7.0.5
Mar 09, 2026
7.0.4
Mar 08, 2026
7.0.3
Mar 05, 2026
7.0.2
Mar 02, 2026
7.0.1
Feb 10, 2026
7.0.0
Feb 01, 2026
6.2.6
Jan 27, 2026
6.2.5
Jan 25, 2026
6.2.4
Dec 15, 2025
6.2.3
Dec 12, 2025
6.2.2
Nov 13, 2025
6.2.1
Oct 12, 2025
6.2.0
Aug 25, 2025
6.1.0
Jun 16, 2025
6.0.0
May 23, 2025
5.5.2
Feb 20, 2025
5.5.1
Jan 21, 2025
5.5.0
Aug 18, 2024
5.4.0
Jul 15, 2024
5.3.3
Feb 26, 2024
5.3.2
Oct 24, 2023
5.3.1
May 27, 2023
5.3.0
Jan 22, 2023
5.2.1
Jan 08, 2023
5.2.0
May 29, 2022
5.1.0
May 15, 2022
5.0.0
Dec 21, 2021
4.2.4
Sep 30, 2021
4.2.3
Sep 29, 2021
4.2.2
Apr 27, 2021
4.2.1
Jan 24, 2021
4.2.0
Dec 10, 2020
4.1.1
Jun 28, 2020
4.1.0
Apr 08, 2020
4.0.0
Dec 15, 2019
3.1.1
May 23, 2019
3.1.0
Jan 29, 2019
3.0.0
Nov 04, 2018
2.1.0
May 12, 2018
2.0.1
Aug 11, 2017
2.0.0
Oct 03, 2016
1.1.6
Apr 01, 2016
1.1.5
Oct 25, 2015
1.1.4
Oct 24, 2015
1.1.3
Sep 15, 2015
1.1.2
Sep 15, 2015
1.1.1
Sep 07, 2015
1.1.0
Aug 28, 2015
1.0.3
Jun 26, 2015
1.0.2
Jun 18, 2015
1.0.1
Jun 06, 2015
1.0.0
Dec 19, 2014
0.8.2
Dec 15, 2014
0.8.1
Dec 07, 2014
0.8.0
Dec 03, 2014
0.7.1
Nov 22, 2014
0.7.0
Nov 12, 2014
0.6.0
Oct 23, 2014
0.5.1
Sep 25, 2014
0.5.0
Sep 23, 2014
0.4.0
Jun 16, 2014
0.3.1
May 07, 2014
0.3.0
May 06, 2014
0.2.0
Apr 02, 2014
0.1.0
Mar 27, 2014
0.0.0
Mar 22, 2014
Wheel compatibility matrix
Files in release
No dependencies