{ "info": { "author": "Hansheng Zhao", "author_email": "copyrighthero@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "Intended Audience :: Information Technology", "Intended Audience :: Science/Research", "Intended Audience :: System Administrators", "License :: OSI Approved :: BSD License", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Topic :: Communications", "Topic :: Database", "Topic :: Internet", "Topic :: Software Development", "Topic :: System", "Topic :: Utilities" ], "description": "###########\nKVS Project\n###########\n\n`README\u4e2d\u6587\u6587\u6863 `_\n\nAbout the KVS Library\n=====================\n\nKVS library is created to easily handle most key-value stores. It supports `redis`, `memcached`, `leveldb` (`plyvel`), Python `dict`, or any other instances with any combinations of (`set`, `put`, `__setitem__`) methods for saving data, (`get`, `__getitem`) methods for getting data and (`delete`, `__delitem__`) methods for deleting data.\n\nThe constructor also takes in `str` as parameter. If one is provided as `':memory:'`, it will simply use a `dict` instance to store information; if strings other than `':memory:'` is provided, it will treat it as a path and use `anydbm` or `dbm` module to open either a `gdbm`, `ndbm` or `dumb` database for storage.\n\nThe module utilizes [SeCo](https://www.github.com/copyrighthero/SeCo) module for data serialization and compression when setting item into database. Since the result parsed by `SeCo` are `bytes` objects, it plays well with third party databases like `redis`, `memcached` and `plyvel`. You can change the default serializer when instantiating, making this library very flexible.\n\nOne might want to use this library to easily interface other databases, to create a in-memory cache, a on-disk cache, etc.\n\nHow to Use KVS Library\n======================\n\nAfter installing using `pip install KVS`, one can simply import kvs and start working.\n\n.. code-block:: python\n\n from kvs import KVS\n from redis import Redis\n from pymemcache.client import Client as Memcached\n import plyvel, shelve, pickle, msgpack\n\n # create databases\n dict_db = {} # yes, simple Python `dict`\n redis = Redis()\n memcached = Memcached()\n leveldb = plyvel('/tmp/testdb', create_if_missing = True)\n shelf = shelve('/tmp/shelvedb')\n\n # instantiate KVS using any one of the following\n kvs = KVS() # default, using python `dict`\n kvs = KVS(':memory:') # the same as above\n kvs = KVS(dict_db) # using the created dict object\n kvs = KVS(redis, pickle) # using redis, and serialize with pickle\n kvs = KVS(memcached, serialize = pickle) # using memcached, serialize with pickle\n kvs = KVS(leveldb, msgpack) # use plyvel and msgpack\n kvs = KVS(shelf, msgpack) # use shelf and msgpack\n # ...\n\n # use the kvs!\n # use .set or .put to set item\n kvs.set('test', 'case') # set an item\n kvs.get('test') # 'case'\n kvs.put('test', 'testcase') # set an item\n # use .get, [key] or . to get\n kvs.get('test') # 'testcase'\n kvs['test'] # 'testcase'\n kvs.test # 'testcase`\n\n # faster operation with __call__ method\n kvs('test', 'call method') # set item\n kvs('test') # 'call method'\n\n # if key does not exist it returns None\n kvs.get('non_exist') # None\n kvs['non_exist'] # None\n kvs.non_exist # None\n kvs('non_exist') # None\n\n # delete with any of the following\n kvs.delete('test')\n del kvs['test']\n del kvs.test\n\n # check if key exists\n 'test' in kvs # False\n kvs('test', 'case')\n 'test' in kvs # True\n\n # get all keys if possible\n list(kvs.keys()) # ['test']\n # get all values if possible\n list(kvs.values()) # ['case']\n # get all items if possible\n list(kvs.items()) # [('test', 'case')]\n\n # other operations\n kvs.pop('test') # 'case'\n kvs.pop('test') # None\n kvs.clear() # clears all items stored in the database\n kvs.sync() # only for `dbm`, otherwise noop\n kvs.optimize() # only for `gdbm`, otherwise noop\n kvs.close() # only for databases with `close` method\n\n # all database attributes are still available,\n # so be careful when using properties to get/set items\n\nKVS Class API References\n========================\n\n`KVS` is the only class exposed in this module, it is the manager and wrapper around actual databases. It takes two parameters, the first being `str` or database instance, the second being the serializer. The class is defaulted to use Python `dict` as database and `SeCo` as the serializer.\n\nSignature: `KVS(database = ':memory:', serialize = None, **kwargs)`\n\nKVS Class\n---------\n\n1. `database` parameter: if passed in as string ':memory:' it will use python `dict` as storage; if passed in as any other string, it will use `anydbm` or `dbm` to open the database; if passed in any other instances, it will use the instance as the database store.\n\n2. `serialize` parameter: if nothing is passed in, the class will use `SeCo` library for data serialization and compression. If any other instance passed in, eg.: `pickle`, `msgpack` etc, it will use it as the serializer. Remember that most databases like `redis`, `memcached` or `leveldb|plyvel` stores only `bytes` objects, keep it in mind when choosing serializers.\n\n`__contains__`: implements the `in` operator.\n`__setitem__`, `set`, `put` method: for setting items.\n`__getitem__`, `get` method: for getting items.\n`__call__`: get or set item depends on how many parameters passed in\n`__delete__`, `delete` method: for deleting items.\n`__setattr__`: almost the alias for `__setitem__`, like `set` or `put` method.\n`__getattr__`: for getting attributes from database instance, if not found, attempts `__getitem__` on `self`.\n`__delattr__`: almost the alias for `__delitem__`, like `delete` method.\n`pop(key)`: pop an item from storage\n`keys()`: keys iterator if possible. eg. not possible with `memcached`.\n`values()`: values iterator if possible. Same reason.\n`items()`: items iterator if possible. Same reason.\n`sync()`: only available to databases with `sync` method, like `dbm` etc, otherwise noop.\n`close()`: only avalable to databases with `close` method, like `plyvel` etc, otherwise noop.\n`clear()`: will invoke database's `clear` or `flush_all`, `flushall` methods to clear the content.\n\nPlease refer to the usage for how to use them :-)\n\nLicenses\n========\n\nThis project is licensed under two permissive licenses, please chose one or both of the licenses to your like. Although not necessary, bug reports or feature improvements, attributes to the author(s), information on how this program is used are welcome and appreciated :-) Happy coding\n\n[BSD-2-Clause License]\n\nCopyright 2018 Hansheng Zhao\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[MIT License]\n\nCopyright 2018 Hansheng Zhao\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "https://www.github.com/copyrighthero/KVS", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://www.github.com/copyrighthero/KVS", "keywords": "KVStore Key-value Store Manager", "license": "BSD-2-Clause + MIT", "maintainer": "", "maintainer_email": "", "name": "KVS", "package_url": "https://pypi.org/project/KVS/", "platform": "", "project_url": "https://pypi.org/project/KVS/", "project_urls": { "Download": "https://www.github.com/copyrighthero/KVS", "Homepage": "https://www.github.com/copyrighthero/KVS", "Source": "https://www.github.com/copyrighthero/KVS" }, "release_url": "https://pypi.org/project/KVS/1.0.0/", "requires_dist": [ "SeCo" ], "requires_python": "", "summary": "Python key-value store manager.", "version": "1.0.0" }, "last_serial": 3692448, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "db7a335bd34540e08ed0379859a4d986", "sha256": "7c47e560601a9559a4056fc4744c20f4e0f1ec0283ebf029510e072b9467b4b3" }, "downloads": -1, "filename": "KVS-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "db7a335bd34540e08ed0379859a4d986", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11425, "upload_time": "2018-03-21T16:54:54", "url": "https://files.pythonhosted.org/packages/64/46/f4777ae3e243b3ba5c871157f6d075978221ff47a644105a5b8c8aa0a1a0/KVS-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "26fe0751762692b6340b35b25ba3cf1d", "sha256": "da5bd2cad6aa7ed3a696dfc41e9063c2cccaf2d4ca17ca44b750a09a8e050cb1" }, "downloads": -1, "filename": "KVS-1.0.0.tar.gz", "has_sig": false, "md5_digest": "26fe0751762692b6340b35b25ba3cf1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8816, "upload_time": "2018-03-21T16:54:56", "url": "https://files.pythonhosted.org/packages/6f/f3/48f9056b06776cc2a2837690b6740f315366251a01b63c5621d92c85b7f3/KVS-1.0.0.tar.gz" } ], "1.0b5": [ { "comment_text": "", "digests": { "md5": "14474448e11163a20bf4e7d95f234e96", "sha256": "5b3a16741544d6aa1d512bd2f87c1860718fd6f8bdd976fe052fdf27bbdec473" }, "downloads": -1, "filename": "KVS-1.0b5-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "14474448e11163a20bf4e7d95f234e96", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7462, "upload_time": "2018-03-21T13:25:56", "url": "https://files.pythonhosted.org/packages/fb/3f/a3feb98b2264a15c33b6fcf272e7cd6b0a042ae05f3e438f433452f0a9a3/KVS-1.0b5-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a98002d7f2fa836bb57630cb73de145d", "sha256": "dacf675d418bc1ae87bc9d80736eebb748721655d943b3bc3b54afee1421aaf7" }, "downloads": -1, "filename": "KVS-1.0b5.tar.gz", "has_sig": false, "md5_digest": "a98002d7f2fa836bb57630cb73de145d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5969, "upload_time": "2018-03-21T13:25:57", "url": "https://files.pythonhosted.org/packages/76/2f/3c9d2ff40a223e76ed546d867ee080652ba8e1b2d3a52836914440f53107/KVS-1.0b5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "db7a335bd34540e08ed0379859a4d986", "sha256": "7c47e560601a9559a4056fc4744c20f4e0f1ec0283ebf029510e072b9467b4b3" }, "downloads": -1, "filename": "KVS-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "db7a335bd34540e08ed0379859a4d986", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11425, "upload_time": "2018-03-21T16:54:54", "url": "https://files.pythonhosted.org/packages/64/46/f4777ae3e243b3ba5c871157f6d075978221ff47a644105a5b8c8aa0a1a0/KVS-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "26fe0751762692b6340b35b25ba3cf1d", "sha256": "da5bd2cad6aa7ed3a696dfc41e9063c2cccaf2d4ca17ca44b750a09a8e050cb1" }, "downloads": -1, "filename": "KVS-1.0.0.tar.gz", "has_sig": false, "md5_digest": "26fe0751762692b6340b35b25ba3cf1d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8816, "upload_time": "2018-03-21T16:54:56", "url": "https://files.pythonhosted.org/packages/6f/f3/48f9056b06776cc2a2837690b6740f315366251a01b63c5621d92c85b7f3/KVS-1.0.0.tar.gz" } ] }