Skip to main content

Description

memoize and keyed-memoize decorators.

  • memo: The classical memoize decorator. It keeps a cache args -> result so you don’t continue to perform the same computations.

  • keymemo(key): This decorator factory act as memo but it permits to specify a key function that takes the args of the decorated function and computes a key value to use as key in the cache dictionary. This way you can for example use a single value of a dictionary as key of the cache, or apply a function before passing something to the cache.

  • instancememo: The classical memoize decorator that can be applied to class functions. It keeps a cache args -> result so you don’t continue to perform the same computations. The cache is kept in the class namespace.

  • instancekeymemo(key): This decorator factory works like a combination of instancememo and keymemo, so it allows to specify a function that generate the cache key based on the function arguments and can be applied to class functions.

Usage

from memo import memo

@memo
def fibonacci(n):
    if n <= 2:
        return 1
    return fibonacci(n-1) + fibonacci(n-2)
from memo import keymemo

@keymemo(lambda tup: tup[0])
def function(tup):
    # build a cache based on the first value of a tuple
    ...

Installation

The package has been uploaded to PyPI, so you can install it with pip:

pip install python-memo

Metadata

Release files for python-memo 0.1.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 python-memo 0.1.0
File Size Uploaded Provenance
python-memo-0.1.0.tar.gz 2.2 kB Without provenance Details

Release files / python-memo-0.1.0.tar.gz

Download URL python-memo-0.1.0.tar.gz
Size 2.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b299488ba0263b04bf2cefde2879b3b26bbd37db53d997c9e656056844dcdba6
BLAKE2b-256 checksum
How to use checksums
50b29c7ab2c1b7832b10d6345088d363ae378aecd5fd1b6beb9a8bf794ec501d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for python-memo 0.1.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.

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

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file 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