Debian Codegraph @

README.md

raw
1 klepto
2 ======
3 persistent caching to memory, disk, or database
4
5 About Klepto
6 ------------
7 ``klepto`` extends Python's ``lru_cache`` to utilize different keymaps and
8 alternate caching algorithms, such as ``lfu_cache`` and ``mru_cache``.
9 While caching is meant for fast access to saved results, ``klepto`` also
10 has archiving capabilities, for longer-term storage. ``klepto`` uses a
11 simple dictionary-sytle interface for all caches and archives, and all
12 caches can be applied to any Python function as a decorator. Keymaps
13 are algorithms for converting a function's input signature to a unique
14 dictionary, where the function's results are the dictionary value.
15 Thus for ``y = f(x)``, ``y`` will be stored in ``cache[x]`` (e.g. ``{x:y}``).
16
17 ``klepto`` provides both standard and *"safe"* caching, where *"safe"* caches
18 are slower but can recover from hashing errors. ``klepto`` is intended
19 to be used for distributed and parallel computing, where several of
20 the keymaps serialize the stored objects. Caches and archives are
21 intended to be read/write accessible from different threads and
22 processes. ``klepto`` enables a user to decorate a function, save the
23 results to a file or database archive, close the interpreter,
24 start a new session, and reload the function and it's cache.
25
26 ``klepto`` is part of ``pathos``, a Python framework for heterogeneous computing.
27 ``klepto`` is in active development, so any user feedback, bug reports, comments,
28 or suggestions are highly appreciated. A list of issues is located at https://github.com/uqfoundation/klepto/issues, with a legacy list maintained at https://uqfoundation.github.io/project/pathos/query.
29
30
31 Major Features
32 --------------
33 ``klepto`` has standard and *"safe"* variants of the following:
34
35 * ``lfu_cache`` - the least-frequently-used caching algorithm
36 * ``lru_cache`` - the least-recently-used caching algorithm
37 * ``mru_cache`` - the most-recently-used caching algorithm
38 * ``rr_cache`` - the random-replacement caching algorithm
39 * ``no_cache`` - a dummy caching interface to archiving
40 * ``inf_cache`` - an infinitely-growing cache
41
42 ``klepto`` has the following archive types:
43
44 * ``file_archive`` - a dictionary-style interface to a file
45 * ``dir_archive`` - a dictionary-style interface to a folder of files
46 * ``sqltable_archive`` - a dictionary-style interface to a sql database table
47 * ``sql_archive`` - a dictionary-style interface to a sql database
48 * ``hdfdir_archive`` - a dictionary-style interface to a folder of hdf5 files
49 * ``hdf_archive`` - a dictionary-style interface to a hdf5 file
50 * ``dict_archive`` - a dictionary with an archive interface
51 * ``null_archive`` - a dictionary-style interface to a dummy archive
52
53 ``klepto`` provides the following keymaps:
54
55 * ``keymap`` - keys are raw Python objects
56 * ``hashmap`` - keys are a hash for the Python object
57 * ``stringmap`` - keys are the Python object cast as a string
58 * ``picklemap`` - keys are the serialized Python object
59
60 ``klepto`` also includes a few useful decorators providing:
61
62 * simple, shallow, or deep rounding of function arguments
63 * cryptographic key generation, with masking of selected arguments
64
65
66 Current Release
67 [![Downloads](https://static.pepy.tech/personalized-badge/klepto?period=total&units=international_system&left_color=grey&right_color=blue&left_text=pypi%20downloads)](https://pepy.tech/project/klepto)
68 [![Conda Downloads](https://img.shields.io/conda/dn/conda-forge/klepto?color=blue&label=conda%20downloads)](https://anaconda.org/conda-forge/klepto)
69 [![Stack Overflow](https://img.shields.io/badge/stackoverflow-get%20help-black.svg)](https://stackoverflow.com/questions/tagged/klepto)
70 ---------------
71 The latest released version of ``klepto`` is available from:
72 https://pypi.org/project/klepto
73
74 ``klepto`` is distributed under a 3-clause BSD license.
75
76
77 Development Version
78 [![Support](https://img.shields.io/badge/support-the%20UQ%20Foundation-purple.svg?style=flat&colorA=grey&colorB=purple)](http://www.uqfoundation.org/pages/donate.html)
79 [![Documentation Status](https://readthedocs.org/projects/klepto/badge/?version=latest)](https://klepto.readthedocs.io/en/latest/?badge=latest)
80 [![Build Status](https://app.travis-ci.com/uqfoundation/klepto.svg?label=build&logo=travis&branch=master)](https://app.travis-ci.com/github/uqfoundation/klepto)
81 [![codecov](https://codecov.io/gh/uqfoundation/klepto/branch/master/graph/badge.svg?token=bk93SHgoDg)](https://codecov.io/gh/uqfoundation/klepto)
82 -------------------
83 You can get the latest development version with all the shiny new features at:
84 https://github.com/uqfoundation
85
86 If you have a new contribution, please submit a pull request.
87
88
89 Installation
90 ------------
91 ``klepto`` can be installed with ``pip``::
92
93 $ pip install klepto
94
95 To include optional archive backends, such as HDF5 and SQL, in the install::
96
97 $ pip install klepto[archives]
98
99 To include optional serializers, such as ``jsonpickle``, in the install::
100
101 $ pip install klepto[crypto]
102
103
104 Requirements
105 ------------
106 ``klepto`` requires:
107
108 * ``python`` (or ``pypy``), **>=3.9**
109 * ``setuptools``, **>=42**
110 * ``dill``, **>=0.4.1**
111 * ``pox``, **>=0.3.7**
112
113 Optional requirements:
114
115 * ``h5py``, **>=2.8.0**
116 * ``pandas``, **>=0.17.0**
117 * ``sqlalchemy``, **>=1.4.0**
118 * ``jsonpickle``, **>=0.9.6**
119 * ``cloudpickle``, **>=0.5.2**
120
121
122 More Information
123 ----------------
124 Probably the best way to get started is to look at the documentation at
125 http://klepto.rtfd.io. Also see ``klepto.tests`` for a set of scripts that
126 test the caching and archiving functionalities in ``klepto``.
127 You can run the test suite with ``python -m klepto.tests``. The
128 source code is also generally well documented, so further questions may
129 be resolved by inspecting the code itself. Please feel free to submit
130 a ticket on github, or ask a question on stackoverflow (**@Mike McKerns**).
131 If you would like to share how you use ``klepto`` in your work, please send
132 an email (to **mmckerns at uqfoundation dot org**).
133
134
135 Citation
136 --------
137 If you use ``klepto`` to do research that leads to publication, we ask that you
138 acknowledge use of ``klepto`` by citing the following in your publication::
139
140 Michael McKerns and Michael Aivazis,
141 "pathos: a framework for heterogeneous computing", 2010- ;
142 https://uqfoundation.github.io/project/pathos
143
144 Please see https://uqfoundation.github.io/project/pathos or
145 http://arxiv.org/pdf/1202.1056 for further information.
146