klepto-0.1.9
Klepto extends python's lru_cache
to utilize different keymaps and alternate caching algorithms, such as lfu_cache
and mru_cache
. While caching is meant for fast access to saved results, klepto also has archiving capabilities, for longer-term storage. Klepto uses a simple dictionary-sytle interface for all caches and archives, and all caches can be applied to any python function as a decorator. Keymaps are algorithms for converting a function's input signature to a unique dictionary, where the function's results are the dictionary value. Thus for y = f(x)
, y
will be stored in cache[x]
(e.g. {x:y}
).
Klepto provides both standard and 'safe' caching, where safe caches are slower but can recover from hashing errors. Klepto is intended to be used for distributed and parallel computing, where several of the keymaps serialize the stored objects. Caches and archives are intended to be read/write accessible from different threads and processes. Klepto enables a user to decorate a function, save the results to a file or database archive, close the interpreter, start a new session, and reload the function and it's cache.
Klepto installs with easy_install or pip:
$ pip install klepto
Klepto requires:
- python, version == 2.7 *or* version >= 3.5 *or* pypy
- dill, version >= 0.3.2
- pox, version >= 0.2.8
Optional requirements:
- sqlalchemy, version >= 0.8.4
(install with $ pip install klepto[archives]
)
- h5py, version >= 2.8.0
(install with $ pip install klepto[archives]
)
- pandas, version >= 0.17.0
(install with $ pip install klepto[archives]
)
Klepto is licensed under 3-clause BSD:
>>> import klepto
>>> print (klepto.license())
To cite klepto:
>>> import klepto
>>> print (klepto.citation())