Skip to main content

provides generic methods to memoize function and method calls

Project description

Memoi

Description

A generic caching mechanism for memoizing function or method calls.

Prerequisites

  • Python >= 3.10

Installation

python -m pip install memoi

Example

from datetime import datetime as dt
from memoi import cached, TextFileRepo

@cached(TextFileRepo('.'))
def f(*args, **kwargs):
    return f"this is the result of the first f() call at {dt.now().isoformat()}"

print(f())
print(f())

This will create a a sqlite database memo.sqlite, keeping track of function calls, and a text file 50/506f353d3ef92d51f3e57bae99367caf directory, containing the result of the first f() call. Obviously the timestamp from the first function call is preserved.

Author

Emanuel Schmid, schmide@ethz.ch

Changelog

Release 0.0.1

Description

Minimum Viable Product of a result caching function decorator.

Added

  • decorator cached: providing a caching mechanism for return values, so the function is not executed the next time when it is called with the same arguments.

  • class TextFileRepo: for caching return values of functions returning strings as text files in a configurable directory.

Release 0.1.0

Description

Multi-String support.

Changed

  • cached: returns a pair of datetime and original result, the former indicating the date of first submission; can handle functions/methods that return iterables.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

memoi-0.1.0-py3-none-any.whl (16.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page