{ "info": { "author": "Jo\u00e3o S. O. Bueno", "author_email": "gwidion@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", "License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)", "Operating System :: OS Independent", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "# Extra Dictionary classes and utilities for Python\n\nNew utilities to be added as they are devised\n\n\n## VersionDict\n\nA Python Mutable Mapping Container (dictionary :-) ) that\ncan \"remember\" previous values.\nUse it wherever you would use a dict - at each\nkey change or update, it's `version` attribute\nis increased by one.\n\n### Special and modified methods:\n\n`.get` method is modified to receive an optional\nnamed `version` parameter that allows one to retrieve\nfor a key the value it contained at that respective version.\nNB. When using the `version` parameter, `get` will raise\na KeyError if the key does not exist for that version and\nno default value is specified.\n\n`.copy(version=None)`: yields a copy of the current dictonary at that version, with history preserved\n(if version is not given, the current version is used)\n\n`.freeze(version=None)` yields a snapshot of the versionDict in the form of a plain dictionary for\nthe specified version\n\n\n### Implementation:\nIt works by internally keeping a list of (named)tuples with\n(version, value) for each key.\n\n\n### Example:\n\n```\n\n>>> from extradict import VersionDict\n>>> a = VersionDict(b=0)\n>>> a[\"b\"] = 1\n>>> a[\"b\"]\n1\n>>> a.get(\"b\", version=0)\n0\n```\n\nFor extra examples, check the \"tests\" directory\n\n## OrderedVersionDict\n\nInherits from VersionDict, but preserves and retrieves key\ninsertion order. Unlike a plain \"collections.OrderedDict\",\nhowever, whenever a key's value is updated, it is moved\nlast on the dictionary order.\n\n### Example:\n```\n>>> from collections import OrderedDict\n>>> a = OrderedDict(((\"a\", 1), (\"b\", 2), (\"c\", 3)))\n>>> list(a.keys())\n>>> ['a', 'b', 'c']\n>>> a[\"a\"] = 3\n>>> list(a.keys())\n>>> ['a', 'b', 'c']\n\n>>> from extradict import OrderedVersionDict\n>>> a = OrderedVersionDict(((\"a\", 1), (\"b\", 2), (\"c\", 3)))\n>>> list(a.keys())\n['a', 'b', 'c']\n>>> a[\"a\"] = 3\n>>> list(a.keys())\n['b', 'c', 'a']\n```\n\n## MapGetter\nA Context manager that allows one to pick variables from inside a dictionary,\nmapping, or any Python object by using the `from import key1, key2` statement.\n\n\n\n```\n>>> from extradict import MapGetter\n>>> a = dict(b=\"test\", c=\"another test\")\n>>> with MapGetter(a) as a:\n... from a import b, c\n...\n>>> print (b, c)\ntest another test\n```\n\nOr:\n```\n>>> from collections import namedtuple\n>>> a = namedtuple(\"a\", \"c d\")\n>>> b = a(2,3)\n>>> with MapGetter(b):\n... from b import c, d\n>>> print(c, d)\n2, 3\n```\n\nIt works with Python 3.4+ \"enum\"s - which is great as it allow one\nto use the enums by their own name, without having to prepend the Enum class\neverytime:\n```\n>>> from enum import Enum\n\n>>> class Colors(tuple, Enum):\n... red = 255, 0, 0\n... green = 0, 255, 0\n... blue = 0, 0, 255\n...\n\n>>> with MapGetter(Colors):\n... from Colors import red, green, blue\n...\n\n>>> red\n\n>>> red[0]\n255\n```\n\nMapGetter can also have a `default` value or callable which\nwill generate values for each name that one tries to \"import\" from it:\n\n```\n>>> with MapGetter(default=lambda x: x) as x:\n... from x import foo, bar, baz\n...\n\n>>> foo\n'foo'\n>>> bar\n'bar'\n>>> baz\n'baz'\n```\n\nIf the parameter default is not a callable, it is assigned directly to\nthe imported names. If it is a callable, MapGetter will try to call it passing\neach name as the first and only positional parameter. If that fails\nwith a type error, it calls it without parameters the way collections.defaultdict\nworks.\n\n\nThe syntax `from import key1 as var1` works as well.\n\n## BijectiveDict\nThis is a bijective dictionary for which each pair key, value added\nis also added as value, key.\n\nThe explictly inserted keys can be retrieved as the \"assigned_keys\"\nattribute - and a dictionary copy with all such keys is available\nat the \"BijectiveDict.assigned\".\nConversely, the generated keys are exposed as \"BijectiveDict.generated_keys\"\nand can be seen as a dict at \"Bijective.generated\"\n\n```\n>>> from extradict import BijectiveDict\n>>>\n>>> a = BijectiveDict(b = 1, c = 2)\n>>> a\nBijectiveDict({'b': 1, 2: 'c', 'c': 2, 1: 'b'})\n>>> a[2]\n'c'\n>>> a[2] = \"d\"\n>>> a[\"d\"]\n2\n>>> a[\"c\"]\nTraceback (most recent call last):\n File \"\", line 1, in \n File \"/home/gwidion/projetos/extradict/extradict/reciprocal_dict.py\", line 31, in __getitem__\n return self._data[item]\nKeyError: 'c'\n>>>\n```\n\n## namedtuple\nAlternate, clean room, implementation of 'namedtuple' as in stdlib's collection.namedtuple\n. This does not make use of \"eval\" at runtime - and can be up to 10 times faster to create\na namedtuple class than the stdlib version.\n\nInstead, it relies on closures to do its magic.\n\nHowever, these will be slower to instantiate tahn stdlib version. The \"fastnamedtuple\"\nis faster in all respects, although it holds the same API for instantiating as tuples, and\nperforms no lenght checking.\n\n\n## fastnamedtuple\nLike namedtuple but the class returned take an iterable for its values\nrather than positioned or named parameters. No checks are made towards the iterable\nlenght, which should match the number of attributes\nIt is faster for instantiating as compared with stdlib's namedtuple\n\n\n## defaultnamedtuple\nImplementation of named-tuple using default parameters -\nEither pass a sequence of 2-tupes (or an OrderedDict) as the second parameter, or\nsend in kwargs with the default parameters, after the first.\n(This takes advantadge of python3.6 + guaranteed ordering of **kwargs for a function\nsee https://docs.python.org/3.6/whatsnew/3.6.html)\n\nThe resulting object can accept positional or named parameters to be instantiated, as a\nnormal namedtuple, however, any omitted parameters are used from the original\nmapping passed to it.\n\n\n## FallbackNormalizedDict\nDictionary meant for text only keys:\nwill normalize keys in a way that capitalization, whitespace and\npunctuation will be ignored when retrieving items.\n\nA parallel dictionary is maintained with the original keys,\nso that strings that would clash on normalization can still\nbe used as separated key/value pairs if original punctuation\nis passed in the key.\n\nPrimary use case if for keeping translation strings when the source\nfor the original strings is loose in terms of whitespace/punctuation\n(for example, in an http snippet)\n\n\n## NormalizedDict\nDictionary meant for text only keys:\nwill normalize keys in a way that capitalization, whitespace and\npunctuation will be ignored when retrieving items.\n\nUnlike FallbackNormalizedDict this does not keep the original\nversion of the keys.\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jsbueno/extradict", "keywords": "versioned bijective assigner getter unpack transactional container collection dict dictionary normalized", "license": "LGPLv3+", "maintainer": "", "maintainer_email": "", "name": "extradict", "package_url": "https://pypi.org/project/extradict/", "platform": "", "project_url": "https://pypi.org/project/extradict/", "project_urls": { "Homepage": "https://github.com/jsbueno/extradict" }, "release_url": "https://pypi.org/project/extradict/0.3.2/", "requires_dist": null, "requires_python": "", "summary": "Enhanced, maybe useful, data containers and utilities: A versioned dictionary, a bidirectional dictionary, and an easy extractor from dictionary key/values to variables", "version": "0.3.2" }, "last_serial": 4540960, "releases": { "0.1.4": [ { "comment_text": "", "digests": { "md5": "327b5532a829fc96326efa95aedb6d6a", "sha256": "61b467aae43a14c0f9d0cd435d5349c211e254fb1f2c73d029fbd622577590e7" }, "downloads": -1, "filename": "extradict-0.1.4.tar.gz", "has_sig": false, "md5_digest": "327b5532a829fc96326efa95aedb6d6a", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6908, "upload_time": "2016-05-27T05:37:07", "url": "https://files.pythonhosted.org/packages/49/f6/56d4037af1b35e6009adf12e5d4f9451139cc303cbd41f836f13d5564719/extradict-0.1.4.tar.gz" } ], "0.1.9": [ { "comment_text": "", "digests": { "md5": "5d292fe59755c9c94a1db56e58621581", "sha256": "992ece25881c0bc8b8bd39cdd1d5e8df9379e5fb3742b919b4f6a42d7b1d9784" }, "downloads": -1, "filename": "extradict-0.1.9.tar.gz", "has_sig": false, "md5_digest": "5d292fe59755c9c94a1db56e58621581", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7675, "upload_time": "2016-05-28T20:05:10", "url": "https://files.pythonhosted.org/packages/42/3c/46736aeded61d4e1fbddb4b25b5ef7c956be53fb9e23a58430d94b72198c/extradict-0.1.9.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "d2d1e22d2820c27a53a3124c7e3a7e8e", "sha256": "4bf371aea931d6aad1ecd6b8655d37eafd11ea3ebd2bf0be8fcdbf22a75d762d" }, "downloads": -1, "filename": "extradict-0.2.0.tar.gz", "has_sig": false, "md5_digest": "d2d1e22d2820c27a53a3124c7e3a7e8e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10284, "upload_time": "2016-05-29T05:50:30", "url": "https://files.pythonhosted.org/packages/b7/b5/e0ddb999f31bae01eec359dad7a6ac3ac694915100fa3f5212371e089d25/extradict-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "6559f022ad6e84fd8da245f55dabfa11", "sha256": "8214f0cb49ae6f903c4bcb3bccec6ed939445b9fbf8343bc9666b1224e9da85b" }, "downloads": -1, "filename": "extradict-0.2.1.tar.gz", "has_sig": false, "md5_digest": "6559f022ad6e84fd8da245f55dabfa11", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10357, "upload_time": "2016-05-30T03:40:48", "url": "https://files.pythonhosted.org/packages/b6/4c/15f6b66ce05dae1365343212df6bf9cac6c025aa8ab18b1f93c0b4cd92ad/extradict-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "81bbc791b7588276abef2d9d76618ce5", "sha256": "beb44cbd820b6bb0937fc0769e285f1a3e6a863dc89a37bfff36b86b19057c67" }, "downloads": -1, "filename": "extradict-0.2.2.tar.gz", "has_sig": false, "md5_digest": "81bbc791b7588276abef2d9d76618ce5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11255, "upload_time": "2016-06-09T20:05:40", "url": "https://files.pythonhosted.org/packages/85/73/14b8fe79b28c1482803e9087a68d8c73ac61a55e6b0afd372566cf46317d/extradict-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "a3471a3236847daa217fde691042c9c3", "sha256": "e5808074147bf9211375a1a3de5687fa8c3f984144cd3c05568befdf7ab7ccbb" }, "downloads": -1, "filename": "extradict-0.2.3.tar.gz", "has_sig": false, "md5_digest": "a3471a3236847daa217fde691042c9c3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12021, "upload_time": "2016-06-18T00:27:18", "url": "https://files.pythonhosted.org/packages/f7/fd/3a68f96c9662f2b245d7119eb910fbec3896ce7c5a3ccdf7e326822f2f66/extradict-0.2.3.tar.gz" } ], "0.2.5": [ { "comment_text": "", "digests": { "md5": "cc4c7e7058de9536ebb0c3fa4ef430e4", "sha256": "a48bb38464525f3d95489ea27a7dc1c6661e53c8e39638efc63c1f7025838223" }, "downloads": -1, "filename": "extradict-0.2.5.tar.gz", "has_sig": false, "md5_digest": "cc4c7e7058de9536ebb0c3fa4ef430e4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15167, "upload_time": "2016-11-30T19:22:11", "url": "https://files.pythonhosted.org/packages/b0/fa/bf77ce90744dd2b238a0d5f5e95661c3d652d4f2b18737501f9b7487ec57/extradict-0.2.5.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "35ac5dbf37d85edcbad01c2ac1dda6b5", "sha256": "94ba2fbe52035c0714c5765dbf4ee70797f53f4cf7fda811bc12454a939d449e" }, "downloads": -1, "filename": "extradict-0.3.tar.gz", "has_sig": false, "md5_digest": "35ac5dbf37d85edcbad01c2ac1dda6b5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17373, "upload_time": "2017-09-27T14:35:29", "url": "https://files.pythonhosted.org/packages/f9/ac/b95a27df3ab620c9bb874e97264c010803a552c144170b1b1a7a915adb9d/extradict-0.3.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "f6f9fdd23e36eabc57f0cf5b69697ae4", "sha256": "86a3539aa0b9045149fcae65540c0ecfd6b2130079e719b382ff71514cb768e6" }, "downloads": -1, "filename": "extradict-0.3.2.tar.gz", "has_sig": false, "md5_digest": "f6f9fdd23e36eabc57f0cf5b69697ae4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18127, "upload_time": "2018-11-29T01:11:03", "url": "https://files.pythonhosted.org/packages/49/66/3c59cc475ce1ef78865e9efdf0b6844b9db087a035286d85017c7a1bcccf/extradict-0.3.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f6f9fdd23e36eabc57f0cf5b69697ae4", "sha256": "86a3539aa0b9045149fcae65540c0ecfd6b2130079e719b382ff71514cb768e6" }, "downloads": -1, "filename": "extradict-0.3.2.tar.gz", "has_sig": false, "md5_digest": "f6f9fdd23e36eabc57f0cf5b69697ae4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 18127, "upload_time": "2018-11-29T01:11:03", "url": "https://files.pythonhosted.org/packages/49/66/3c59cc475ce1ef78865e9efdf0b6844b9db087a035286d85017c7a1bcccf/extradict-0.3.2.tar.gz" } ] }