cachetools
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.
Release files for cachetools 7.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| cachetools-7.2.0.tar.gz | 41.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cachetools-7.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 58.0 kB
Release files / cachetools-7.2.0.tar.gz
| Download URL | cachetools-7.2.0.tar.gz |
|---|---|
| Size | 41.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bcac1a1b8da6909994a2957238a57b8140dab7c5c5c69a43669654fe87a33c1d
|
|
BLAKE2b-256 checksum How to use checksums |
292c3f18755527b03ca9ff6be724bd5370cb777c76a87f17301377cf04a4729b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / cachetools-7.2.0-py3-none-any.whl
| Download URL | cachetools-7.2.0-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3045213f186b89fdd95d94441354c4bd87c570b7a38d8c3fd1d9dd37f6dc90d8
|
|
BLAKE2b-256 checksum How to use checksums |
ccbb1c6e7a89b11da19f137e4ef5a5c5fe47a5bb686449ba343944ccf8fb34b2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|