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.
Metadata
Release files for cachetools 7.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cachetools-7.2.3.tar.gz | 43.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cachetools-7.2.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 62.1 kB
Release files / cachetools-7.2.3.tar.gz
| Download URL | cachetools-7.2.3.tar.gz |
|---|---|
| Size | 43.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6fafd06de4a5bd915ff7d247588ea497e28c9a568c62db8678d9a5f11515a9a
|
|
BLAKE2b-256 checksum How to use checksums |
098827fe0785c7a9aa285c753db0b4ea967adbf76128fede66379c35a4b8d054
|
| 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.3-py3-none-any.whl
| Download URL | cachetools-7.2.3-py3-none-any.whl |
|---|---|
| Size | 18.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85ef9d2703918bedf7f88caa0b06bb3bb7a71360eb0b05c20796b89fede6e30c
|
|
BLAKE2b-256 checksum How to use checksums |
fbdd044062b61d94c59c29ad0da6918e6a21106f5b115096e9c87081cdd96167
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for cachetools 7.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.