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 details)

Uploaded Python 3

File details

Details for the file memoi-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: memoi-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.10.13

File hashes

Hashes for memoi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b6867bf896f46ab3be5f6ebe4b49c5b268a8f8092e2c5a508fbc37e4c174c91
MD5 77e19784bb9990c542fc95ab0755f0c5
BLAKE2b-256 096c95cca586d1bfade73ef7305cd94b9608ad2823afb4b2903239c4bda92a91

See more details on using hashes here.

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