{ "info": { "author": "Pedro Buteri Gonring", "author_email": "pedro@bigode.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "Intended Audience :: System Administrators", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Database", "Topic :: Utilities" ], "description": "|Build Status| |Coverage| |Version| |Supported| |License|\n\ndbj\n===\n\ndbj is a simple embedded in memory json database.\n\nIt is easy to use, fast and has a simple query language.\n\nThe code is fully documented, tested and beginner friendly with around 400 LOC.\n\nOnly the standard library is used and it works on Python 2.7, Python 3.4+ and PyPy 2.7.\n\n\nUsage\n=====\n\n.. code-block:: python\n\n >>> from dbj import dbj\n >>> db = dbj('mydb.json')\n\n >>> # Insert using an auto generated uuid1 key\n >>> db.insert({'name': 'John', 'age': 18})\n 'a71d90ce0c7611e995faf23c91392d78'\n\n >>> # Insert using a supplied key, in this case 'user:anab'\n >>> user = {'name': 'Ana Beatriz', 'age': 10, 'username': 'anab'}\n >>> db.insert(user, 'user:anab')\n 'user:anab'\n\n >>> db.insert({'name': 'Bob', 'age': 30})\n 'cc6ddfe60c7611e995faf23c91392d78'\n\n >>> db.get('a71d90ce0c7611e995faf23c91392d78')\n {'name': 'John', 'age': 18}\n\n >>> db.get('user:anab')\n {'name': 'Ana Beatriz', 'age': 10, 'username': 'anab'}\n\n >>> db.find('age >= 18')\n ['a71d90ce0c7611e995faf23c91392d78', 'cc6ddfe60c7611e995faf23c91392d78']\n\n >>> db.find('name == \"ana beatriz\"')\n ['user:anab']\n\n >>> r = db.find('name == \"John\" or name == \"Bob\" and age > 10')\n >>> db.getmany(r)\n [{'name': 'Bob', 'age': 30}, {'name': 'John', 'age': 18}]\n\n >>> # Sort the result by age\n >>> r = db.sort(r, 'age')\n >>> db.getmany(r)\n [{'name': 'John', 'age': 18}, {'name': 'Bob', 'age': 30}]\n\n >>> db.save()\n True\n\n\nInstall\n=======\n\nInstall using pip::\n\n $ pip install dbj\n\n\nExamples\n========\n\nCheck the `available commands`_ for a full list of supported methods.\n\nImport the module and create a new database:\n\n.. code-block:: python\n\n >>> from dbj import dbj\n >>> db = dbj('mydb.json')\n\nInsert a few documents with auto generated key:\n\n.. code-block:: python\n\n >>> doc = {'name': 'John Doe', 'age': 18}\n >>> db.insert(doc)\n '7a5ebd420cb211e98a0ff23c91392d78'\n\n >>> docs = [{'name': 'Beatriz', 'age': 30}, {'name': 'Ana', 'age': 10}]\n >>> db.insertmany(docs)\n 2\n\nInsert with a supplied key:\n\n.. code-block:: python\n\n >>> doc = {'name': 'john', 'age': 20, 'country': 'Brasil'}\n >>> db.insert(doc, '1')\n 1\n\n >>> db.insert({'name': 'Bob', 'age': 40}, '2')\n 2\n\n >>> db.getallkeys()\n ['7a5ebd420cb211e98a0ff23c91392d78', 'db21baf80cb211e98a0ff23c91392d78', 'db21edde0cb211e98a0ff23c91392d78', '1', '2']\n\nPop and delete:\n\n.. code-block:: python\n\n >>> db.delete('1')\n True\n\n >>> db.poplast()\n {'name': 'Bob', 'age': 40}\n\n >>> db.size()\n 3\n\n >>> db.getallkeys()\n ['7a5ebd420cb211e98a0ff23c91392d78', 'db21baf80cb211e98a0ff23c91392d78', 'db21edde0cb211e98a0ff23c91392d78']\n\nUpdating an existing document:\n\n.. code-block:: python\n\n >>> db.insert({'name': 'Ethan', 'age': 40}, '1000')\n '1000'\n\n >>> db.get('1000')\n {'name': 'Ethan', 'age': 40}\n\n >>> db.update('1000', {'age': 50})\n True\n\n >>> db.get('1000')\n {'name': 'Ethan', 'age': 50}\n\n >>> db.update('1000', {'name': 'Ethan Doe', 'gender': 'male'})\n True\n\n >>> db.pop('1000')\n {'name': 'Ethan Doe', 'age': 50, 'gender': 'male'}\n\nRetrieving some documents:\n\n.. code-block:: python\n\n >>> db.getall()\n [{'name': 'John Doe', 'age': 18}, {'name': 'Beatriz', 'age': 30}, {'name': 'Ana', 'age': 10}]\n\n >>> db.getfirst()\n {'name': 'John Doe', 'age': 18}\n\n >>> db.getlast()\n {'name': 'Ana', 'age': 10}\n\n >>> db.getrandom() # returns a random document\n {'name': 'Ana', 'age': 10}\n\nCheck for existance:\n\n.. code-block:: python\n\n >>> db.exists('7a5ebd420cb211e98a0ff23c91392d78')\n True\n\nSearchin and sorting:\n\n.. code-block:: python\n\n >>> r = db.sort(db.getallkeys(), 'name')\n >>> db.getmany(r)\n [{'name': 'Ana', 'age': 10}, {'name': 'Beatriz', 'age': 30}, {'name': 'John Doe', 'age': 18}]\n\n >>> r = db.find('name ?= \"john\"')\n >>> db.getmany(r)\n [{'name': 'John Doe', 'age': 18}]\n\n >>> query = 'name == \"john doe\" or name == \"ana\" and age >= 10'\n >>> r = db.find(query)\n >>> db.getmany(r)\n [{'name': 'John Doe', 'age': 18}, {'name': 'Ana', 'age': 10}]\n\n >>> r = db.find('age < 40')\n >>> r = db.sort(r, 'age')\n >>> db.getmany(r)\n [{'name': 'Ana', 'age': 10}, {'name': 'John Doe', 'age': 18}, {'name': 'Beatriz', 'age': 30}]\n\nSave the database to disk:\n\n.. code-block:: python\n\n >>> db.save()\n True\n\nEnable auto saving to disk after a insert, update or delete:\n\n.. code-block:: python\n\n >>> db = dbj('mydb.json', autosave=True)\n\n\nAbout the simple query language\n===============================\n\nThe query for the find command uses the following pattern:\n\n*field operator value and/or field operator value...*\n\n**Spaces are mandatory** and used as a separator by the parser. For example,\nthe following query **will not work**::\n\n name==\"John\" and age >=18\n\n**A valid example**::\n\n name == \"John Doe\" and age >= 18\n\nStrings must be enclosed by quotes. Quoted text can be searched using double\nquotes as the string delimiter, like::\n\n name == \"\"Bob \"B\" Lee\"\"\n\nPlease note that if value is a string, a search for text will be executed\n(using the string operatos below) and if value is a number, a number comparison\nsearch will be used.\n\nThe supported string operators are::\n\n '==' -> Exact match. 'John' will not match 'John Doe' but will match 'john'\n by default. If case sensitive is desired, just use find with sens=True. See\n available commands below for the full find method signature.\n\n '?=' -> Partial match. In this case, 'John' will match 'John Doe'.\n\n '!=' -> Not equal operator.\n\nThe numbers comparison operators are::\n\n '==', '!=', '<', '<=', '>', '>='\n\nThe supported logical operatos are::\n\n and, or\n\n\nImportant changes\n=================\n\n0.1.4:\n------\n\n- The insert() method will raise a TypeError exception if the document dict is not json serializable.\n\n\nPerformance\n===========\n\nSince the entire database is an OrderedDict in memory, performance is pretty\ngood. On a cheap single core VM it can handle dozens of thousands operations\nper second.\n\nA simple benchmark is included to get a roughly estimative of operations per\nsecond. Here is the result on a $5 bucks Linode VM running on Pyhton 3::\n\n $ python3 bench_dbj.py\n\n --------------------------------\n\n Inserting 100000 documents using auto generated uuid1 key...\n Done! Time spent: 4.44s\n Inserted: 100000\n Rate: 22515 ops/s\n\n --------------------------------\n\n Clearing the database...\n Done!\n\n --------------------------------\n\n Inserting 100000 documents using a supplied key...\n Done! Time spent: 1.26s\n Inserted: 100000\n Rate: 79563 ops/s\n\n --------------------------------\n\n Retrieving 100000 documents one at a time...\n Done! Time spent: 1.54s\n Retrieved: 100000\n Rate: 64754 ops/s\n\n --------------------------------\n\n Saving database to disk...\n Done! Time spent: 1.06s\n\n --------------------------------\n\n Deleting 100000 documents one at a time...\n Done! Time spent: 0.24s\n Deleted: 100000\n Rate: 419770 ops/s\n\n --------------------------------\n\n Removing file...\n Done!\n\n Peak memory usage: 60.41 MB\n\n\nAvailable commands\n==================\n\ninsert(document, key=None) -> Create a new document on database.\n Args:\n | document (dict): The document to be created.\n | key (str, optional): The document unique key. Defaults to uuid1.\n Returns:\n The document key.\n\ninsertmany(documents) -> Insert multiple documents on database.\n Args:\n documents (list): List containing the documents to insert.\n Returns:\n Number of inserted documents.\n\nsave() -> Save database to disk.\n Returns:\n True if successful.\n\nclear() -> Remove all documents from database.\n Returns:\n True if successful.\n\nsize() -> Return the database size.\n Returns:\n Number of documents on database.\n\nexists(key) -> Check if a document exists on database.\n Args:\n key (str): The document key.\n Returns:\n True or False if it does not exist.\n\ndelete(key) -> Delete a document on database.\n Args:\n key (str): The document key.\n Returns:\n True or False if it does not exist.\n\ndeletemany(keys) -> Delete multiple documents on database.\n Args:\n keys (list): List containing the keys of the documents to delete.\n Returns:\n Number of deleted documents.\n\nupdate(key, values) -> Add/update values on a document.\n Args:\n | key (str): The document key.\n | values (dict): The values to be added/updated.\n Returns:\n True or False if document does not exist.\n\nupdatemany(keys, values) -> Add/update values on multiple documents.\n Args:\n | keys (list): List containing the keys of the documents to update.\n | values (dict): The values to be added/updated.\n Returns:\n Number of updated documents.\n\nget(key) -> Get a document on database.\n Args:\n key (str): The document key.\n Returns:\n The document or False if it does not exist.\n\ngetmany(keys) -> Get multiple documents from database.\n Args:\n keys (list): List containing the keys of the documents to retrieve.\n Returns:\n List of documents.\n\ngetall() -> Return a list containing all documents on database.\n Returns:\n List with all database documents.\n\ngetallkeys() -> Return a list containing all keys on database.\n Returns:\n List with all database keys.\n\ngetrandom() -> Get a random document on database.\n Returns:\n A document or False if database is empty.\n\ngetfirst(self) -> Get the first inserted document on database.\n Returns:\n The first inserted document or False if database is empty.\n\ngetlast() -> Get the last inserted document on database.\n Returns:\n The last inserted document or False if database is empty.\n\ngetfirstkey() -> Get the first key on database.\n Returns:\n The first key or False if database is empty.\n\ngetlastkey() -> Get the last key on database.\n Returns:\n The last key or False if database is empty.\n\npop(key) -> Get the document from database and remove it.\n Args:\n key (str): The document key.\n Returns:\n The document or False if it does not exist.\n\npopfirst() -> Get the first inserted document on database and remove it.\n Returns:\n The first inserted document or False if database is empty.\n\npoplast() -> Get the last inserted document on database and remove it.\n Returns:\n The last inserted document or False if database is empty.\n\nsort(keys, field, reverse=False) -> Sort the documents using the field provided.\n Args:\n | keys (list): List containing the keys of the documents to sort.\n | field (str): Field to sort.\n | reverse (bool, optional): Reverse search. Defaults to False.\n Returns:\n Sorted list with the documents keys.\n\nfindtext(field, text, exact=False, sens=False, inverse=False, asc=True) -> Simple text search on the provided field.\n Args:\n | field (str): The field to search.\n | text (str): The value to be searched.\n | exact (bool, optional): Exact text match. Defaults to False.\n | sens (bool, optional): Case sensitive. Defaults to False.\n | inverse (bool, optional): Inverse search, return the documents that do not match the search. Defaults to False.\n | asc (bool, optional): Ascii conversion before matching, this matches text like 'cafe' and 'caf\u00e9'. Defaults to True.\n Returns:\n List with the keys of the documents that matched the search.\n\nfindnum(expression) -> Simple number comparison search on provided field.\n Args:\n | expression (str): The comparison expression to use, e.g., \"age >= 18\". The pattern is 'field operator number'.\n Returns:\n List with the keys of the documents that matched the search.\n\nfind(query, sens=False, asc=True) -> Simple query like search.\n Args:\n | query (str): The query to use.\n | sens (bool, optional): Case sensitive. Defaults to False.\n | asc (bool, optional): Ascii conversion before matching, this matches text like 'cafe' and 'caf\u00e9'. Defaults to True.\n Returns:\n List with the keys of the documents that matched the search.\n\n\n.. |Build Status| image:: https://travis-ci.org/pdrb/dbj.svg?branch=master\n :target: https://travis-ci.org/pdrb/dbj\n\n.. |Coverage| image:: https://coveralls.io/repos/github/pdrb/dbj/badge.svg?branch=master\n :target: https://coveralls.io/github/pdrb/dbj?branch=master\n\n.. |Version| image:: https://badge.fury.io/py/dbj.svg\n :target: https://pypi.org/project/dbj/\n\n.. |Supported| image:: https://img.shields.io/pypi/pyversions/dbj.svg\n :target: https://pypi.org/project/dbj/\n\n.. |License| image:: https://img.shields.io/pypi/l/dbj.svg\n :target: https://github.com/pdrb/dbj/blob/master/LICENSE", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pdrb/dbj", "keywords": "simple json database", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dbj", "package_url": "https://pypi.org/project/dbj/", "platform": "", "project_url": "https://pypi.org/project/dbj/", "project_urls": { "Homepage": "https://github.com/pdrb/dbj" }, "release_url": "https://pypi.org/project/dbj/0.1.6/", "requires_dist": null, "requires_python": "", "summary": "Simple embedded in memory json database", "version": "0.1.6" }, "last_serial": 5764484, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "3be461931efb6de815b9f9f7ea8f6d61", "sha256": "4cad30617f72d1f8e0a0db59eb9e180bbffedd417eab4efcf0a9adb8d681e7aa" }, "downloads": -1, "filename": "dbj-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3be461931efb6de815b9f9f7ea8f6d61", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8502, "upload_time": "2018-12-31T06:27:56", "url": "https://files.pythonhosted.org/packages/e9/79/5c9146ae22a8a7f13363c8d468af09db33e5546384caa3dd7f6c3862b94a/dbj-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "82472ba46052bef4fc8ff0454a0ee6a5", "sha256": "47ba3f796ed57808a9c4d9be563e5b1b5e7b076a393f2fa386e277eab992443c" }, "downloads": -1, "filename": "dbj-0.1.1.tar.gz", "has_sig": false, "md5_digest": "82472ba46052bef4fc8ff0454a0ee6a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8776, "upload_time": "2018-12-31T20:23:28", "url": "https://files.pythonhosted.org/packages/3a/00/3c996a97f89d837ac4cb0d3b9ef1b955d54a6e2f1fe253abe70b9054c9cf/dbj-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "4c5764d8260dce148f4b9a16e21bb002", "sha256": "7eaace1b3d91ea31de5badbb2d8259ebcfeb1ab66628c4566493aebed617996f" }, "downloads": -1, "filename": "dbj-0.1.2.tar.gz", "has_sig": false, "md5_digest": "4c5764d8260dce148f4b9a16e21bb002", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10265, "upload_time": "2019-01-02T15:41:08", "url": "https://files.pythonhosted.org/packages/37/dd/04f78733b4115afd3476810ca1cbf9c9f93ce7bf1144be34cbed633cd6d9/dbj-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "614edd0eefb473ff3c4ca7251dc7041c", "sha256": "c64fae956a7f9cd952ffac784430bbb3de77e649f0fbbda6f9964c1be534c490" }, "downloads": -1, "filename": "dbj-0.1.3.tar.gz", "has_sig": false, "md5_digest": "614edd0eefb473ff3c4ca7251dc7041c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10527, "upload_time": "2019-01-02T18:54:13", "url": "https://files.pythonhosted.org/packages/26/30/627be822afba96dc2631d178b5be871d151890762e8f999bc93420464dd1/dbj-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "3d395ea993bf8bdc0d5410ac90e2bd7f", "sha256": "24eacb5a5af48978e3a47679d1de4f65a50e487787b2793d9fde00fb862b4164" }, "downloads": -1, "filename": "dbj-0.1.4.tar.gz", "has_sig": false, "md5_digest": "3d395ea993bf8bdc0d5410ac90e2bd7f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10770, "upload_time": "2019-01-10T01:09:58", "url": "https://files.pythonhosted.org/packages/f5/83/ebf2ca1d1bdb5f90f02ff7e57431239f43ca71d83ef5cc9bb6b34d1bfa88/dbj-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "575c29af1cf1cc62543086cfceb9e88b", "sha256": "0715b01f7c5cc433f02c66c56ddcaa7c1b4c490ca1f830412513964380013fbd" }, "downloads": -1, "filename": "dbj-0.1.5.tar.gz", "has_sig": false, "md5_digest": "575c29af1cf1cc62543086cfceb9e88b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10794, "upload_time": "2019-01-12T03:32:14", "url": "https://files.pythonhosted.org/packages/7d/bb/e36e31bdd39e3f600ddab2d719b79d393c547a04e608bc397d48436fa9fd/dbj-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "890081573ad7aa0a10eee2304dd27769", "sha256": "cbf5f88a8e4368cf1bcecaafa45db528dd23995a4aaf7a8a5d5ad7bb97236f91" }, "downloads": -1, "filename": "dbj-0.1.6.tar.gz", "has_sig": false, "md5_digest": "890081573ad7aa0a10eee2304dd27769", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10804, "upload_time": "2019-08-31T14:43:37", "url": "https://files.pythonhosted.org/packages/c2/33/256a98a8022675d335a66500d1a357a3671bc21616b453efbffc433e2125/dbj-0.1.6.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "890081573ad7aa0a10eee2304dd27769", "sha256": "cbf5f88a8e4368cf1bcecaafa45db528dd23995a4aaf7a8a5d5ad7bb97236f91" }, "downloads": -1, "filename": "dbj-0.1.6.tar.gz", "has_sig": false, "md5_digest": "890081573ad7aa0a10eee2304dd27769", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10804, "upload_time": "2019-08-31T14:43:37", "url": "https://files.pythonhosted.org/packages/c2/33/256a98a8022675d335a66500d1a357a3671bc21616b453efbffc433e2125/dbj-0.1.6.tar.gz" } ] }