{ "info": { "author": "Istv\u00e1n P\u00e1sztor", "author_email": "pasztorpisti@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 2", "Programming Language :: Python :: 3", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "============\ndictionaries\n============\n\nPython dictionary implementations\n\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n\n\n.. image:: https://img.shields.io/travis/pasztorpisti/py-dictionaries.svg?style=flat\n :target: https://travis-ci.org/pasztorpisti/py-dictionaries\n :alt: build\n\n.. image:: https://img.shields.io/codacy/9920e31609734de8815aa995b70b96e7/master.svg?style=flat\n :target: https://www.codacy.com/app/pasztorpisti/py-dictionaries\n :alt: code quality\n\n.. image:: https://landscape.io/github/pasztorpisti/py-dictionaries/master/landscape.svg?style=flat\n :target: https://landscape.io/github/pasztorpisti/py-dictionaries/master\n :alt: code health\n\n.. image:: https://img.shields.io/coveralls/pasztorpisti/py-dictionaries/master.svg?style=flat\n :target: https://coveralls.io/r/pasztorpisti/py-dictionaries?branch=master\n :alt: coverage\n\n.. image:: https://img.shields.io/pypi/v/dictionaries.svg?style=flat\n :target: https://pypi.python.org/pypi/dictionaries\n :alt: pypi\n\n.. image:: https://img.shields.io/github/tag/pasztorpisti/py-dictionaries.svg?style=flat\n :target: https://github.com/pasztorpisti/py-dictionaries\n :alt: github\n\n.. image:: https://img.shields.io/github/license/pasztorpisti/py-dictionaries.svg?style=flat\n :target: https://github.com/pasztorpisti/py-dictionaries/blob/master/LICENSE.txt\n :alt: license: MIT\n\n\n.. contents::\n\n\nQuick overview\n==============\n\n- Attribute-style item access is provided by all dictionary classes of this library.\n- 5 dictionary implementations:\n\n - Standard dictionaries with attribute-style item access and a smarter ``copy()`` method with update parameters:\n\n - ``Dict``\n - ``OrderedDict``\n\n - Immutable/hashable versions of the previous two dictionaries:\n\n - ``FrozenDict``\n - ``FrozenOrderedDict``\n\n - A wrapper that can be used to create a readonly view of another dictionary instance:\n\n - ``ReadonlyDictProxy``\n\n\nInstallation\n============\n\n.. code-block:: sh\n\n pip install dictionaries\n\nAlternatively you can download the distribution from the following places:\n\n- https://pypi.python.org/pypi/dictionaries#downloads\n- https://github.com/pasztorpisti/py-dictionaries/releases\n\n\nUsage\n=====\n\n\nQuick-starter\n-------------\n\nAfter installing the library you can import the dictionary classes the following way:\n\n.. code-block:: python\n\n from dictionaries import Dict, OrderedDict, FrozenDict, FrozenOrderedDict, ReadonlyDictProxy\n\n\nTheir interface is as standard as possible so I assume you know how to deal with them.\n\n\nAttribute-style item access\n---------------------------\n\nThe attribute-style dictionary item access can be really convenient in many cases but it has issues. The most\nobvious issue is that the attributes of the dictionary are in conflict with your item keys.\nFor this reason attribute-style access is a little bit \"stinky\" (especially when you try to implement it) and\nto aid this problem I've recently come up with a different kind of attribute-style access implementation. This\nlibrary provides both the usual way (discussed here and there) and also my method. (Yes, I know that providing 2 or\nmore ways isn't pythonic but you have to experiment to find out what works and what doesn't...) Later I might\ndrop one of them.\n\n\n\"Classic\" attribute-style dict item access (as people know it)\n..............................................................\n\nAs mentioned previously the attributes of the dictionary instance (like ``copy``) conflict with the keys of\nyour items. In order to be able to access dictionary methods we have to provide priority for the dictionary\nattributes over the item keys.\n\n.. code-block:: python\n\n >>> from dictionaries import Dict\n >>> d = Dict(copy=True, name='example')\n >>> d.my_item = 5 # this is equivalent to d['my_item'] = 5\n >>> d\n {'my_item': 5, 'name': 'example', 'copy': True}\n >>> d.my_item\n 5\n >>> d.name\n 'example'\n >>> d.copy # the 'copy' item conflicts with the copy method!!!\n \n\n\nAttribute-style item access through the ``items`` attribute of the dictionary\n.............................................................................\n\nMy recent invention aids the previous conflict between dictionary attributes and item keys. By typing\na little bit more you can use attribute-style access without worrying about conflicts:\n\n.. code-block:: python\n\n >>> from dictionaries import Dict\n >>> d = Dict(copy=True, name='example')\n >>> d.items.my_item = 5\n >>> d\n {'my_item': 5, 'name': 'example', 'copy': True}\n >>> d.items.my_item\n 5\n >>> d.items.name\n 'example'\n >>> d.items.copy\n True\n >>> d.items() # using items() the good old way still works\n dict_items([('my_item', 5), ('name', 'example'), ('copy', True)])\n\n\nYou can use the ``items`` \"method\" of your dictionary the old way by calling it but you can also use it as an\nobject that provides attribute style access to your items. There are no conflicts because the only attributes\nof ``items`` are the keys of your dictionary items.\n\nBesides attribute-style item access the ``items`` attribute provides a limited set of the typical dictionary interface:\n\n- ``__contains__``, ``__iter__``, ``__len__``\n- Item assignment/retrieval/deletion with both attribute-style access and subscript notation.\n\nThis can be useful if you have to pass around the ``items`` object to be accessed elsewhere.\n\n.. code-block:: python\n\n >>> from dictionaries import Dict\n >>> d = Dict(copy=True, name='example', my_item=5)\n >>> 'name' in d\n True\n >>> iter(d.items)\n \n >>> list(d.items)\n ['my_item', 'name', 'copy']\n >>> len(d.items)\n 3\n >>> del d.items['name']\n >>> del d.items.copy # no conflict with Dict.copy :-)\n >>> d\n {'my_item': 5}\n\n\nDictionary classes\n==================\n\n\n``FrozenDict`` and ``FrozenOrderedDict``\n----------------------------------------\n\nThese are \"frozen\"/immutable like the ``frozenset`` provided by the standard library. After creation\ntheir value doesn't change during their lifetime. Like other immutable objects, instances of\nthese dictionaries are hashable given that all objects inside them are also hashable.\n\n.. code-block:: python\n\n >>> from dictionaries import FrozenDict\n >>> d = FrozenDict(item1=1, item2=2)\n >>> d['item3'] = 3 # we shouldn't be able to modify an immutable object\n Traceback (most recent call last):\n File \"\", line 1, in \n TypeError: 'FrozenDict' object does not support item assignment\n >>> del d['item2'] # we shouldn't be able to modify an immutable object\n Traceback (most recent call last):\n File \"\", line 1, in \n TypeError: 'FrozenDict' object does not support item deletion\n >>> d\n \n >>> hash(d)\n 8310388587437647073\n\n\n``ReadonlyDictProxy``\n---------------------\n\nSometimes you have to pass around some of your dictionaries but you want to make sure that no one modifies them. In this\ncase what you should do is creating a ``ReadonlyDictProxy`` wrapper around your dictionary and passing around the\nwrapper instead of your original wrapped one. The ``ReadonlyDictProxy`` instance will delegate all requests to your\noriginal dictionary except those requests that involve data modification (like item assignment/deletion, ``update()``,\netc...). Of course if you modify the wrapped dictionary then the users of the readonly proxy will notice the changes.\nThe proxy keeps most of the behavior provided by the wrapped dict, for example if the wrapped dict is an ordered one\nthen the readonly proxy also behaves as ordered.\n\n.. code-block:: python\n\n >>> from dictionaries import ReadonlyDictProxy, OrderedDict\n >>> wrapped = OrderedDict.fromkeys(['item1', 'item2', 'item3'])\n >>> proxy = ReadonlyDictProxy(wrapped)\n >>> wrapped\n OrderedDict([('item1', None), ('item2', None), ('item3', None)])\n >>> proxy\n \n\n\nChanges to the wrapped dict instance are reflected by the readonly proxy:\n\n.. code-block:: python\n\n >>> del wrapped['item3']\n >>> wrapped['new_item'] = 'brand new'\n >>> wrapped\n OrderedDict([('item1', None), ('item2', None), ('new_item', 'brand new')])\n >>> proxy\n \n\n\nTrying to modify the proxy object will fail:\n\n.. code-block:: python\n\n >>> proxy['trying hard'] = 'to assign' # the proxy is readonly, assignment fails\n Traceback (most recent call last):\n File \"\", line 1, in \n TypeError: 'ReadonlyDictProxy' object does not support item assignment\n >>> del proxy['item1'] # the proxy is readonly, deletion fails\n Traceback (most recent call last):\n File \"\", line 1, in \n TypeError: 'ReadonlyDictProxy' object does not support item deletion\n\n\nCopying a ``ReadonlyDictProxy`` instance with its ``copy`` method creates another\n``ReadonlyDictProxy`` instance that wraps the exact same object:\n\n.. code-block:: python\n\n >>> # Both of these statements create another wrapper/proxy around wrapped:\n >>> proxy_copy = proxy.copy()\n >>> proxy_copy2 = ReadonlyDictProxy(wrapped)\n >>>\n >>> # Now we have 3 proxy objects wrapping the same dictionary (wrapped):\n >>> wrapped.clear()\n >>> wrapped.items.woof = 'woof'\n >>> proxy\n \n >>> proxy_copy\n \n >>> proxy_copy2\n \n\n\nExtended ``copy`` method\n------------------------\n\nAll dictionary classes except ``ReadonlyDictProxy`` have a ``copy`` method that receives ``**kwargs``. These\nkeyword arguments are treated as dictionary items and used to create a copy that is updated with them.\n\n.. code-block:: python\n\n >>> from dictionaries import Dict\n >>> d = Dict(a=0, b=1)\n >>> d2 = d.copy(b=2, c=3)\n >>> d\n {'a': 0, 'b': 1}\n >>> d2\n {'a': 0, 'b': 2, 'c': 3}", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/pasztorpisti/py-dictionaries", "keywords": "Dict FrozenDict FrozenOrderedDict ReadonlyDictProxy ordered readonly frozen proxy attribute access", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "dictionaries", "package_url": "https://pypi.org/project/dictionaries/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/dictionaries/", "project_urls": { "Homepage": "https://github.com/pasztorpisti/py-dictionaries" }, "release_url": "https://pypi.org/project/dictionaries/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Dict implementations with attribute access: ReadonlyDictProxy, FrozenDict, FrozenOrderedDict, Dict, OrderedDict", "version": "0.0.1" }, "last_serial": 2079600, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "e74238e0af0910e8d4067714a955a475", "sha256": "16e9b7e337ccbeabdf02ee829f81e3c9bd4477e343ab477d06b4d7e7184764a7" }, "downloads": -1, "filename": "dictionaries-0.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e74238e0af0910e8d4067714a955a475", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11080, "upload_time": "2016-04-19T00:59:20", "url": "https://files.pythonhosted.org/packages/0a/cc/330c7eac5a7a73d1fda572df3d424cd37ffa05a5770020a06c6073cfacd8/dictionaries-0.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7bb1df647dcf342bd3e0408e19764f52", "sha256": "c0ee10b9b5072cd7cc8ccb864e37f95c6422e7c673591f74b6a1ca9041e1b8cf" }, "downloads": -1, "filename": "dictionaries-0.0.0.tar.gz", "has_sig": false, "md5_digest": "7bb1df647dcf342bd3e0408e19764f52", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11406, "upload_time": "2016-04-19T00:59:25", "url": "https://files.pythonhosted.org/packages/42/46/cf4f9808f62861bb505563b3c41c30e83c59680c42e76c3289b2432fd5e4/dictionaries-0.0.0.tar.gz" } ], "0.0.1": [ { "comment_text": "", "digests": { "md5": "c11518a3dae7e6c442823d1377490cb5", "sha256": "26e0c57694d5e01b648c058939d69fbdc6d0caf04cd5b70cb7b4a69e577c1c31" }, "downloads": -1, "filename": "dictionaries-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c11518a3dae7e6c442823d1377490cb5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11131, "upload_time": "2016-04-23T04:14:30", "url": "https://files.pythonhosted.org/packages/4d/54/b45e79bcfb116b7f946cb91f3955618b01a1f80dc0ee85da0d68fcc5f318/dictionaries-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7b571458aaba5f747022aec7bc94bd13", "sha256": "1ec6d4b2e2c5762a7423f66a3b423bc976439137e1537df5a164ea040abca2cb" }, "downloads": -1, "filename": "dictionaries-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7b571458aaba5f747022aec7bc94bd13", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11438, "upload_time": "2016-04-23T04:15:41", "url": "https://files.pythonhosted.org/packages/1b/fb/1de9ebe1b7c1d253f93a854f9b94ede7e839cc0535137d01c8492433413a/dictionaries-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c11518a3dae7e6c442823d1377490cb5", "sha256": "26e0c57694d5e01b648c058939d69fbdc6d0caf04cd5b70cb7b4a69e577c1c31" }, "downloads": -1, "filename": "dictionaries-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c11518a3dae7e6c442823d1377490cb5", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 11131, "upload_time": "2016-04-23T04:14:30", "url": "https://files.pythonhosted.org/packages/4d/54/b45e79bcfb116b7f946cb91f3955618b01a1f80dc0ee85da0d68fcc5f318/dictionaries-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7b571458aaba5f747022aec7bc94bd13", "sha256": "1ec6d4b2e2c5762a7423f66a3b423bc976439137e1537df5a164ea040abca2cb" }, "downloads": -1, "filename": "dictionaries-0.0.1.tar.gz", "has_sig": false, "md5_digest": "7b571458aaba5f747022aec7bc94bd13", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11438, "upload_time": "2016-04-23T04:15:41", "url": "https://files.pythonhosted.org/packages/1b/fb/1de9ebe1b7c1d253f93a854f9b94ede7e839cc0535137d01c8492433413a/dictionaries-0.0.1.tar.gz" } ] }