Skip to main content

cachetools

Latest PyPI version CI build status Documentation build status Test coverage License

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):
    from urllib.request import urlopen
    url = 'https://peps.python.org/pep-%04d/' % num
    with urlopen(url) as s:
        return s.read()

# cache PyOWM weather data for no longer than ten minutes
from pyowm.owm import OWM
owm = OWM('your-free-api-key')

@cached(cache=TTLCache(maxsize=1024, ttl=600))
def get_weather(place):
    return owm.weather_manager().weather_at_place(place).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 8.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cachetools 8.0.3
File Size Uploaded Provenance Actions
cachetools-8.0.3.tar.gz 52.6 kB Without provenance Details for cachetools-8.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cachetools 8.0.3
File Interpreter ABI Platform Actions
cachetools-8.0.3-py3-none-any.whl Python 3 none any Details for cachetools-8.0.3-py3-none-any.whl

Total release size: 72.2 kB

Release files / cachetools-8.0.3.tar.gz

Download URL cachetools-8.0.3.tar.gz
Size 52.6 kB
Tags Source
SHA-256 checksum
How to use checksums
79245d0d90464e29355f13658cd769e57d98ed06242d3c6fbd71796ca0938ef9
BLAKE2b-256 checksum
How to use checksums
de4ae1204e16df86b6381abdba73cde2e59cda5fbedb110400f335c5dd86fade
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / cachetools-8.0.3-py3-none-any.whl

Download URL cachetools-8.0.3-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
08bc12eeb7c7ab68abbe2d64d07fd7923ff532e32ff04ae27d22add1c5e8a5f9
BLAKE2b-256 checksum
How to use checksums
314850e8de023394349623d6065fd4a8d2a52cc5cc06d9ac96d0e765a5bf556c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for cachetools 8.0.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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

8.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page