{ "info": { "author": "Miguel Garcia Diaz (aka Zeycus)", "author_email": "zeycus@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3.5", "Topic :: Database" ], "description": "========================================\nPersistent dictionaries based on mongoDB\n========================================\n\nA class :class:`Mongo_shelve` is implemented, that provides a `dict`-like interface for `mongoDB `_ collections.\n\n\nMotivation\n==========\n\nFor a long time Python has included the :mod:`shelve` module, an implementation of persistent dictionaries based on :mod:`dbm`, which in turn saves information in local text files. I have used them myself, but for hundreds of thousands of entries performance was far from ideal. Inserting a single new entry would take nearly a second.\n\nA simple test helped me realize that replacing :mod:`shelve` with mongodb speed was about x50 or better for that project [#f1]_.\n\nAnother relevant plus is that decent mongoDB servers include safety options, backup systems, etc., so data is safer than in a local file.\n\nFinally, I know pretty much nothing about multi-threading, but it seems mongoDB has a decent support for concurrent access, while I understand :mod:`shelve` has none.\n\n\nProject Description\n===================\n\nA class :class:`Mongo_shelve` is implemented providing a `dict`-like interface for a `mongoDB `_ collection. All usual `dict` operations are supported. On the other hand, powerful interfaces of mongoDB collections like `delete_many` are preserved. See the class documentation for details.\n\nI am currently using Python 3.6 on Windows. I have not tested this code in other versions or platforms.\n\n\nWarning\n=======\n\nTo be able to use mongoDB, we must have a connection to a mongoDB server. It could be our own machine, a hosting service, etc. If you are new to mongoDB, several tutorials are available, `this `_ is one of them. There are also many mongoDB-hosting services that provide free sandboxes with a decent size, no need to spend a dime just to experiment.\n\nIf you have mongoDB installed, to serve it locally (in Windows) just run:\n\n.. code:: bash\n\n mongod.exe --dbpath=\n\n\nWarning regarding tests\n=======================\n\nTo be able to run tests, we need a mongoDB server to connect to (I know of no better way. If there is, please let me know). The tests are written asumming that a local server is running, building a client that connects to it, creates testing databases/collections, fills them, accesses information stored, and wipe them all in the end.\n\n\nUsage Example\n=============\n\nThe example below asummes that a local mongoDB server is running (thus the IP 127.0.0.1) and in the default 27017 port.\n\n.. code:: python\n\n # Creation of a mongodb client\n import pymongo\n client = pymongo.MongoClient(\"127.0.0.1:27017\")\n db = client['tvs761_hashes']\n col = db['files'] # This is the collection that will be used as dict\n\n # Creation of the Mongo_shelve instance, choosing 'filename' as look-up field.\n ms = Mongo_shelve(col=col, keyField='filename')\n\n # Some basic operations\n print(\"There are %s entries.\" % len(ms))\n\n # Insertion of new information\n ms['myBestJoke.txt'] = dict(size=14461)\n print(\"Info stored: %s\" % ms['myBestJoke.txt'])\n print(\"There are %s entries.\" % len(ms))\n\n # Updating information\n ms['myBestJoke.txt'] = dict(size=14732)\n print(\"Info stored: %s\" % ms['myBestJoke.txt'])\n\n # Deletion\n del ms['myBestJoke.txt']\n print(\"There are %s entries.\" % len(ms))\n\n # Traversing is easy\n for key, data in ms.items():\n print(\"For key '%s' the information stored is %s\" % (key, data))\n\n # Collection 'delete_many': remove information for files smaller than 1 KB.\n ms.delete_many({'size': {\"$lt\": 1024}})\n\n # Delete all entries\n ms.clear()\n\n\n\n.. rubric:: Footnotes\n\n.. [#f1] I was using the least refined `dbm.dumb` manager.\n Theoretically, with Berkeley's `dbm.ndbm` or GNU's `dmb.gnu` performance would have been better, but I was unable to install them at the time.\n\n", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/zeycus/mongo_shelve/", "keywords": "shelve persistent dictionary", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "mongo_shelve", "package_url": "https://pypi.org/project/mongo_shelve/", "platform": "", "project_url": "https://pypi.org/project/mongo_shelve/", "project_urls": { "Homepage": "https://github.com/zeycus/mongo_shelve/" }, "release_url": "https://pypi.org/project/mongo_shelve/0.1/", "requires_dist": null, "requires_python": "", "summary": "Persistent dictionaries based on mongoDB", "version": "0.1" }, "last_serial": 3301049, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "f3bcf85bf839f97ab6912c7a1a6b907d", "sha256": "c693e89dc3ba9afb9e75973201996dda6ebc06277754ee3638c1df6816756ab8" }, "downloads": -1, "filename": "mongo_shelve-0.1.tar.gz", "has_sig": false, "md5_digest": "f3bcf85bf839f97ab6912c7a1a6b907d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4699, "upload_time": "2017-11-02T18:41:09", "url": "https://files.pythonhosted.org/packages/c8/4f/d1a26ec3e1486ba12e1ad297fa78b6aa124addf947b8c7e66a2aea7f4bbd/mongo_shelve-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f3bcf85bf839f97ab6912c7a1a6b907d", "sha256": "c693e89dc3ba9afb9e75973201996dda6ebc06277754ee3638c1df6816756ab8" }, "downloads": -1, "filename": "mongo_shelve-0.1.tar.gz", "has_sig": false, "md5_digest": "f3bcf85bf839f97ab6912c7a1a6b907d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4699, "upload_time": "2017-11-02T18:41:09", "url": "https://files.pythonhosted.org/packages/c8/4f/d1a26ec3e1486ba12e1ad297fa78b6aa124addf947b8c7e66a2aea7f4bbd/mongo_shelve-0.1.tar.gz" } ] }