Skip to main content
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):
    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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cachetools-7.1.8.tar.gz (40.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cachetools-7.1.8-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file cachetools-7.1.8.tar.gz.

File metadata

  • Download URL: cachetools-7.1.8.tar.gz
  • Upload date:
  • Size: 40.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for cachetools-7.1.8.tar.gz
Algorithm Hash digest
SHA256 1221d547a0b24b7f26fa891d40d488b5258beab9aebd8ed68c729be3af849c43
MD5 07d2259165edb64a98c9c894914ca738
BLAKE2b-256 4b399a4689914dd907915cee74733b95888fc1d8a21aad47a24a0a2deec73ac4

See more details on using hashes here.

File details

Details for the file cachetools-7.1.8-py3-none-any.whl.

File metadata

  • Download URL: cachetools-7.1.8-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for cachetools-7.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a81e3844acaa7355b6567f97bd67a94a14ec3a9bc2cbbdae45b9592cc036775b
MD5 1b862340ab11d5aa7e1ae4c00bedcb25
BLAKE2b-256 d73d9487690d0e937854db587205c66bab3c3cf88d9f00ed380b74cb88cc94ee

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

7.1.8 This release

2 files

7.1.7

2 files

7.1.6

2 files

7.1.5

2 files

7.1.4

2 files

7.1.3

2 files

7.1.2

2 files

7.1.1

2 files

7.1.0

2 files

7.0.6

2 files

7.0.5

2 files

7.0.4

2 files

7.0.3

2 files

7.0.2

2 files

7.0.1

2 files

7.0.0

2 files

6.2.6

2 files

6.2.5

2 files

6.2.4

2 files

6.2.3

2 files

6.2.2

2 files

6.2.1

2 files

6.2.0

2 files

6.1.0

2 files

6.0.0

2 files

5.5.2

2 files

5.5.1

2 files

5.5.0

2 files

5.4.0

2 files

5.3.3

2 files

5.3.2

2 files

5.3.1

2 files

5.3.0

2 files

5.2.1

2 files

5.2.0

2 files

5.1.0

2 files

5.0.0

2 files

4.2.4

2 files

4.2.3

2 files

4.2.2

2 files

4.2.1

2 files

4.2.0

2 files

4.1.1

2 files

4.1.0

2 files

4.0.0

2 files

3.1.1

2 files

3.1.0

2 files

3.0.0

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.1.6

2 files

1.1.5

2 files

1.1.4

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.1

2 files

0.7.0

1 file

0.6.0

1 file

0.5.1

1 file

0.5.0

1 file

0.4.0

1 file

0.3.1

1 file

0.3.0

1 file

0.2.0

1 file

0.1.0

1 file

0.0.0

1 file

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