{ "info": { "author": "Leonardo Giordani", "author_email": "giordani.leonardo@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Natural Language :: English", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3" ], "description": "DictRegister\n============\n\n|Build Status| |Version| |PyPi Downloads|\n\nDocumentation\n-------------\n\n`dictregister\ndocumentation `__\n\n**dictregister** provides an object that contains an ordered list of\ndictionaries with some functions to search and manage them.\n\nDictionaries are useful objects, as they can easily represent complex\nobjects; being a basic language structure in Python they are very handy:\nas an instance, they are serialiable, and if you ever worked with JSON\nyou are accustomed to see them around.\n\nWhen dealing with more than one dictionary, namely a list of them, a\nproblem arises: searching the list for dictionaries is complex and you\nusually write a bunch of repeated code to get the information you need.\n\n**dictregister** acts as a standard Python list but can contain only\ndictionaries (actually objects implementing collections.Mapping);\nadditionally, it provides functions to search and manage dictionaries by\nkey, to manage single keys and to store more than one value for each\nkey.\n\n**dictregister** is a pure Python package, but its syntax has been\nheavily influenced by Django's query syntax, so Django users will find\nat home.\n\nIndeed, **dictregister** acts like a small key/value database. Please\nnote that there it stores values in memory and there is no optimization,\nso use it for small collections.\n\nBasic usage\n-----------\n\nThe ``DictRegister`` object acts as a ``list``, so you can either\ninitialize it empty\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister()\n\nor with an iterable object as an argument\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}])\n\nand you can use any method of ``list`` like ``append()``\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister()\n dr.append({'x':1, 'y':2})\n\n``DictRegister`` accepts only objects that inherit from the\n``collections.Mapping`` Abstract Base Class. If you try to insert an\nobject that does not stick with this rule you will receive a\n``TypeError``.\n\nManaging keys\n-------------\n\nYou can manage keys in batch mode with ``kadd()``, ``kreplace()``, and\n``kremove()``.\n\nAdding a key to each element is easy with ``kadd()``\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}])\n dr == [{'x':1, 'y':2}, {'x':3, 'y':4}]\n dr.kadd('z', 5)\n dr == [{'x':1, 'y':2, 'z':5}, {'x':3, 'y':4, 'z':5}]\n\nPlease note that if you add more than a value to the same key you get a\nmultiple-value element, which is treated in a special way. See the\nMultiple values section below.\n\nWhen you remove keys you can do it unconditionally\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}])\n dr == [{'x':1, 'y':2}, {'x':3, 'y':4}]\n dr.kremove('y')\n dr == [{'x':1}, {'x':3}]\n\nwhich removes all keys with that name. or you can specify a value, in\nwhich case only the elments that match both the key and the value will\nbe removed.\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}])\n dr == [{'x':1, 'y':2}, {'x':3, 'y':4}]\n dr.kremove('y',4)\n dr == [{'x':1, 'y':2}, {'x':3}]\n\nLast, you can replace the value of a key\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}])\n dr == [{'x':1, 'y':2}, {'x':3, 'y':4}]\n dr.kreplace('x',6)\n dr == [{'x':6, 'y':2}, {'x':6, 'y':4}]\n\nAdvanced usage\n--------------\n\nYou can find a subset of dictionaries using ``dfilter()``\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}])\n filtdr = dr.dfilter(x=1)\n filtdr == [{'x':1, 'y':2}]\n\nYou can pass as many conditions as you want to ``dfilter()``\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}])\n filtdr = dr.dfilter(x=1)\n filtdr == [{'x':1, 'y':2}, {'x':1, 'y':6}]\n filtdr = dr.dfilter(x=1, y=2)\n filtdr == [{'x':1, 'y':2}]\n\nYou can easily get only the first element of the filtering with\n``dget()``. Remember that while ``dfilter()`` silently accepts a search\nthat returns no values, returning an empty ``DictRegister``, ``dget()``\nraises an ``IndexError`` exception.\n\nYou can remove elements from a ``DictRegister`` object with\n``dremove()``, which returns a ``DictRegister`` containing the removed\nelements.\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}])\n filtdr = dr.dremove(x=1)\n dr == [{'x':3, 'y':4}]\n filtdr == [{'x':1, 'y':2}, {'x':1, 'y':6}]\n\nOtherwise you obtain a new object with the elements removed\n``dremove_copy()``\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}])\n filtdr = dr.dremove_copy(x=1)\n dr == [{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}]\n filtdr == [{'x':3, 'y':4}]\n\nLast you can pop an element with ``dpop()``, which returns the first\nelement matching the given conditions. Remember that ``dpop()`` raises\n``IndexError`` if no matching element is found.\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}])\n filtdr = dr.dpop(x=1)\n dr == [{'x':3, 'y':4}, {'x':1, 'y':6}]\n\nRemember that, being a list, ``DictRegister`` also provides you a\n``pop([i])`` method that pops the element at index ``i`` or the first\nelement if ``i`` is not specified.\n\nNote that ``dfilter()``, ``dremove()``, and ``dremove_copy()`` return a\n``DictRegister`` so you can easily chain calls.\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}])\n filtdr = dr.dfilter(x=1).dremove_copy(y=2)\n dr == [{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}]\n filtdr == [{'x':1, 'y':6}]\n\nMatching elements\n-----------------\n\nWhen using the advanced features of ``DictRegister`` like filtering you\ncan use a special syntax for keys, namely a ``key__operator`` syntax.\n\nThe implicit operator is ``eq``, which matches all dictionaries with the\ngiven key with the given value.\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}])\n filtdr = dr.dfilter(x__eq=3)\n filtdr == [{'x':3, 'y':4}]\n filtdr = dr.dfilter(x=3)\n filtdr == [{'x':3, 'y':4}]\n\nThe inequality can be matched with ``ne``\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6}])\n filtdr = dr.dfilter(x__ne=1)\n filtdr == [{'x':3, 'y':4}]\n\nYou can match dictionaries that contain or not a given key\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}, {'x':1, 'y':6, 'z':8}])\n filtdr = dr.dfilter(z__iskey=True)\n filtdr == [{'x':1, 'y':6, 'z':8}]\n filtdr = dr.dfilter(z__iskey=False)\n filtdr == [{'x':1, 'y':2}, {'x':3, 'y':4}]\n\nMultiple values\n---------------\n\nThe ``DictRegister`` object can contain any dictionary with a single\nvalue for each key, like\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister()\n dr.append({'x':1, 'y':2})\n\nIf you store more than a value for a key, ``DictRegister`` uses a set to\nhost the values. You are free to append dictionaries with generic\nsequences, most notably lists and sets, as values. However remeber that\n``DictRegister`` does not consider the sequence itself as the value of\nthe key, but the contained elements; so if you need to store a sequence\nas a value you have to store a ``set`` that contains the sequence.\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':1, 'y':2}, {'x':3, 'y':4}])\n dr == [{'x':1, 'y':2}, {'x':3, 'y':4}]\n dr.kadd('x', 2)\n dr == [{'x':set([1, 2]), 'y':2}, {'x':set([2, 3]), 'y':4}]\n\nYou can match multiple values with the ``in`` and ``nin`` operators. The\nfirst matches all dictionaries that contain the given key with the given\nvalue among its values, while ``nin`` performs the opposite match.\n\n.. code:: python\n\n import dictregister\n dr = dictregister.DictRegister([{'x':set([1, 2]), 'y':2}, {'x':2, 'y':4}])\n filtdr = dr.dfilter(x__in=2)\n filtdr == [{'x':set([1, 2]), 'y':2}, {'x':2, 'y':4}]\n\nAs you can see ``DictRegister`` treats keys with a single value and with\nmultiple values in the same way.\n\nInstallation\n------------\n\n.. code:: sh\n\n pip install dictregister\n\nContributions\n-------------\n\nAny form of contribution is warmly welcomed. Feel free to submit issues\nof to make changes and submit a pull request. being the first Python\npackage I ship with all the bells and whistles like distutils, tests and\nfriends, I gladly accept suggestions or corrections on this topic.\n\nThanks\n------\n\nMany thanks to `Jeff Knupp `__ for\nhis post `Open Sourcing a Python Project the Right\nWay `__.\n\nMany thanks to `Audrey M. Roy `__ for her\n`cookiecutter `__ and\n`cookiecutter-pypackage `__\ntools, which heavily simplified the implementation of the whole thing.\n\n.. |Build Status| image:: https://travis-ci.org/lgiordani/dictregister.png?branch=master\n :target: https://travis-ci.org/lgiordani/dictregister\n.. |Version| image:: https://badge.fury.io/py/dictregister.png\n :target: http://badge.fury.io/py/dictregister\n.. |PyPi Downloads| image:: https://pypip.in/d/dictregister/badge.png\n :target: https://crate.io/packages/dictregister?version=latest\n\n\n\n\nHistory\n-------\n\n0.9.0 (2013-11-08)\n++++++++++++++++++\n\n* First implementation\n\n0.9.0.post1 (2013-11-08)\n++++++++++++++++++\n\n* Fixed PyPI classifiers\n\n0.9.1 (2013-11-14)\n++++++++++++++++++\n\n* Added a direct import of DictRegister in __init__.py (thanks to https://github.com/Jeff17Robbins)\n\n0.9.2 (2013-11-14)\n++++++++++++++++++\n\n* Fixed import in __init__.py for Python 3, now all tox tests pass\n\n1.0.0 (2013-12-04)\n++++++++++++++++++\n\n* Raise TypeError instead of ValueError if invalid object is passed (pull request from joshgeller)", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/lgiordani/dictregister", "keywords": "dictregister", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "dictregister", "package_url": "https://pypi.org/project/dictregister/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/dictregister/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/lgiordani/dictregister" }, "release_url": "https://pypi.org/project/dictregister/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "A searchable list of dictionaries", "version": "1.0.0" }, "last_serial": 935505, "releases": { "0.9.0.post1": [ { "comment_text": "", "digests": { "md5": "076b594bd87df54afbbbb1e43722c1bf", "sha256": "cb265d628a655567274a58413fddbfc768006affac382ae3a7a67974cbeeffd5" }, "downloads": -1, "filename": "dictregister-0.9.0.post1.tar.gz", "has_sig": false, "md5_digest": "076b594bd87df54afbbbb1e43722c1bf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9810, "upload_time": "2013-11-08T15:32:14", "url": "https://files.pythonhosted.org/packages/22/a4/fe8eef473b3647a5c3d41d179b04505a69ae512015c21d376d9caa8a6d94/dictregister-0.9.0.post1.tar.gz" } ], "0.9.1": [ { "comment_text": "", "digests": { "md5": "725bad53c46fbea8214266df86be29f6", "sha256": "776be767b68cf74d689154735064c4b3b9eea7f3b19c47f50344987c89211ad6" }, "downloads": -1, "filename": "dictregister-0.9.1.tar.gz", "has_sig": false, "md5_digest": "725bad53c46fbea8214266df86be29f6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9876, "upload_time": "2013-11-14T08:06:32", "url": "https://files.pythonhosted.org/packages/c2/46/94a9ea178c4a2beeeef8d2d386bc562087b94dfdac5e94f7ad9342bda884/dictregister-0.9.1.tar.gz" } ], "0.9.2": [ { "comment_text": "", "digests": { "md5": "549f380e92dd3d699f8f73fb28ac4b2b", "sha256": "3cd38f997426118d5b87b9d41fbcb834110a7706e2ccc140fd945afaa0a7cda0" }, "downloads": -1, "filename": "dictregister-0.9.2.tar.gz", "has_sig": false, "md5_digest": "549f380e92dd3d699f8f73fb28ac4b2b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9948, "upload_time": "2013-11-14T08:25:22", "url": "https://files.pythonhosted.org/packages/2c/cd/f7eaabaa24b6f13eb8ae7aba3b11c6e4ca264fe488e9507d88631b52ff13/dictregister-0.9.2.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "2d32489fc48a70fe7fff1a77da5b595b", "sha256": "9bb2b996ae96c74890b6f8c59081ac1fe22b0d9e638a8d625b181ce4825fb962" }, "downloads": -1, "filename": "dictregister-1.0.0.tar.gz", "has_sig": false, "md5_digest": "2d32489fc48a70fe7fff1a77da5b595b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10012, "upload_time": "2013-12-04T10:02:01", "url": "https://files.pythonhosted.org/packages/6d/df/eaa1cd1bed1382c15c68fbd2c87b1f852cb876c50f7414a50a4367fdb8c7/dictregister-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2d32489fc48a70fe7fff1a77da5b595b", "sha256": "9bb2b996ae96c74890b6f8c59081ac1fe22b0d9e638a8d625b181ce4825fb962" }, "downloads": -1, "filename": "dictregister-1.0.0.tar.gz", "has_sig": false, "md5_digest": "2d32489fc48a70fe7fff1a77da5b595b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10012, "upload_time": "2013-12-04T10:02:01", "url": "https://files.pythonhosted.org/packages/6d/df/eaa1cd1bed1382c15c68fbd2c87b1f852cb876c50f7414a50a4367fdb8c7/dictregister-1.0.0.tar.gz" } ] }