Skip to main content

reckon: Dead-simple, dynamic memoization

image image image image image codecov Code style: black

Installation

In order to install the latest version, simply pip3 install -U reckon.

This library requires Python 3.6 or greater.

What is it?

reckon implements a dynamic LRU cache by automatically monitoring the memory usage of your machine and purging entries as it approaches a pre-defined ratio (defaults to 90%).

reckon is largely inspired by the global_lru_cache package, so credit should be given for the initial implementation. This package brings those ideas into python3 and adds a local cache implementation as well.

Usage

Usage is simple:

import reckon

@reckon.memoize
def some_expensive_func(foo: int, bar: int):
    return foo ** bar

reckon will automatically make use of the global cache.

While the global cache is automatically maintained, it may be necessary to managed the cache manually. To that purpose, reckon provides the following global methods:

  • reckon.glob.clear: Clear the global cache.
  • reckon.glob.shrink: Shrink the global cache.
  • reckon.glob.usage: Check the current usage ratio.
  • reckon.glob.set_usage: Set the max memory usage ratio for the global cache.
  • reckon.glob.info: View high-level information about the cache - similar to functools.lru_cache.cache_info

If you wish to only maintain a cache local to a function you can simply pass a flag to the decorator:

import reckon

@reckon.memoize(locale="local")
def some_expensive_func(foo: int, bar: int):
    return foo ** bar

Additionally, if you wish to maintain a cache local to a module, you can initialize your own instance of the LocalCache object:

import reckon

cache = reckon.local()

@cache.memoize
def some_expensive_func(foo: int, bar: int):
    return foo ** bar

The local cache instance maintains the same high-level API for management as the global cache:

  • LocalCache.clear: Clear the local cache.
  • LocalCache.shrink: Shrink the local cache.
  • LocalCache.usage: Check the current usage ratio.
  • LocalCache.set_usage: Set the max memory usage ratio for the local cache.
  • LocalCache.info: View high-level information about the cache - similar to functools.lru_cache.cache_info

All memoized functions have introspection into their cache via the cache attribute.

Documentation

Full documentation coming soon!

How to Contribute

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Create a branch on Github for your issue or fork the repository on GitHub to start making your changes to the master branch.
  3. Write a test which shows that the bug was fixed or that the feature works as expected.
  4. Send a pull request and bug the maintainer until it gets merged and published. :)

Metadata

Release files for reckon 0.2.0

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

Source distribution (sdist)

Source distribution for reckon 0.2.0
File Size Uploaded Provenance
reckon-0.2.0.tar.gz 8.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for reckon 0.2.0
File Interpreter ABI Platform
reckon-0.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 16.9 kB

Release files / reckon-0.2.0.tar.gz

Download URL reckon-0.2.0.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e6133d72a076869ad7f46f8aee12277d3f0d874ad4eae0a05fe33f6536dde027
BLAKE2b-256 checksum
How to use checksums
aca68e339445d9b11e30d57fd764b3082a006d4d093215787f12a6a6bfc9cd96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Release files / reckon-0.2.0-py2.py3-none-any.whl

Download URL reckon-0.2.0-py2.py3-none-any.whl
Size 8.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
1812389b46f46cf8fa96654a798c43495ef50cd155cc3e90b7c24929c628c7b6
BLAKE2b-256 checksum
How to use checksums
0f4f723513cac87843ab2387c699d61ceecbc23ba98eab3c19c2ab1b21cd33e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

Security for reckon 0.2.0

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.

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