{ "info": { "author": "LuckyDams", "author_email": "LuckyDams@gmail.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "# Attr-Dict \n\nYet another Attribute Dict implementation ! \n\nThis package provides a dictionary with attribute access to keys. It is especially convenient when working with deeply nested data. (Original idea from https://github.com/otsaloma/attd)\n\n\n**Different implementations** based on `OrderedDict`: \n\n- **Strict**: **`AttrDict`** \n Work as a dictionary with class attribute syntax. Some keys cannot be translated to attributes (like int), in this case revert to usual dict syntax (ie: dict[key]). \n\n- **Lazy**: **`LazyAttrDict`** \n Based on AttrDict but return None on missing keys, and mask values (list of keys on repr()).\n\n- **Restricted**: **`RestrictedAttrDict`** \n Lazy Attribute dictionary enforcing value change from dictionary syntax only (setitem & delitem), and masking values (return list of keys on repr()). \n\n Will raise AttributeError on Attribute change (setattr or delattr) to mimic @property attribute. \n\n\n#### Basic usage:\n```python\n# Some dict\n>>> conf_A = {'a': 1, 'b': 2, 'c': 3}\n>>> conf_B = {'a': 11, 'b': 12, 'c': {'c1': 13, 'c2': 23}}\n\n# import library\n>>> from attr_dict import AttrDict, LazyAttrDict, RestrictedAttrDict\n\n\n## Create a Lazy Attribute Dict\n>>> lad = LazyAttrDict()\n\n# Add some data (using different syntax)\n>>> lad.A = conf_A\n>>> lad['B']= conf_B\n\n# or\n>>> lad.update(dict(A=conf_A, B=conf_B))\n\n# Access data\n>>> lad\n{'A': {'a': 1, 'b': 2, 'c': 3}, 'B': {'a': 11, 'b': 12, 'c': {'c1': 13, 'c2': 23}}}\n>>> lad.A\n{'a': 1, 'b': 2, 'c': 3}\n>>> lad.A.c\n3\n>>> lad['A']['c']\n3\n>>> 'c' in lad.A\nTrue\n```\n\n\n#### Other features:\n```python\n# Export to JSON\n>>> json_data = lad.to_json()\n>>> print(json_data)\n{\n \"A\": {\n \"a\": 1,\n \"b\": 2,\n \"c\": 3\n },\n \"B\": {\n \"a\": 11,\n \"b\": 12,\n \"c\": {\n \"c1\": 13,\n \"c2\": 23\n }\n }\n}\n\n## Import JSON to a new Attribute Dict\n>>> new_ad = AttrDict().from_json(json_data)\n>>> print(new_ad)\nAttrDict([('A', AttrDict([('a', 1), ('b', 2), ('c', 3)])), \\\n('B', AttrDict([('a', 11), ('b', 12), ('c', AttrDict([('c1', 13), ('c2', 23)]))]))])\n\n\n## Use Restricted Attribute Dict\n>>> rad = RestrictedAttrDict()\n\n# Add data using dict syntax (setitem)\n>>> rad['A'] = {}\n>>> rad['A']['a'] = 1\n>>> for k,v in conf_A.items():\n... rad['A'][k] = v\n...\n\n# Data access to values is restricted\n>>> rad\n['A']\n>>> rad.A\n['a', 'b', 'c']\n>>> rad.A.b\n2\n>>> dict(rad.A)\n{'a': 1, 'b': 2, 'c': 3}\n\n\n# Attributes are protected\n>>> rad.A = conf_A # doctest: +ELLIPSIS\nTraceback (most recent call last):\n...\nAttributeError: can't set attribute\n\n>>> rad.A.b = 0 # doctest: +ELLIPSIS\nTraceback (most recent call last):\n...\nAttributeError: can't set attribute\n>>> del rad.A.b # doctest: +ELLIPSIS\nTraceback (most recent call last):\n...\nAttributeError: can't delete attribute\n\n# Use dict syntax to change or delete\n>>> rad.A['b'] = 0\n>>> rad.A.pop('b')\n0\n\n# Missing key return None\n>>> print(rad.A.b)\nNone\n>>> 'b' in rad.A\nFalse\n``` \n\n\nRelative interfaces named '**indexes**' are also available to manage any king of objects with these attribute dictionaries: \n**`AttrIndex`**, **`LazyIndex`**, **`RestrictedIndex`** \n(current implementation only works on 2 levels) \n\n#### Index usage:\n```python\n# Import & init\n>>> from attr_dict import LazyIndex\n>>> x = LazyIndex()\n\n# set keys & args\n>>> x.set_arg('A', a=1, b=2, c=3)\n>>> x.set_key('B')\n\n>>> x.index\n{'A': {'a': 1, 'b': 2, 'c': 3}, 'B': {}}\n\n# get, del & check\n>>> x.get_key('A')\n{'a': 1, 'b': 2, 'c': 3}\n>>> x.get_arg('A', 'b')\n2\n\n>>> x.del_arg('A', 'c')\n>>> x.get_key('A')\n{'a': 1, 'b': 2}\n\n>>> x.check_arg('A', 'b', 2)\nTrue\n```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/LuckyDams/Attr-Dict", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Attr-Dict", "package_url": "https://pypi.org/project/Attr-Dict/", "platform": "any", "project_url": "https://pypi.org/project/Attr-Dict/", "project_urls": { "Homepage": "https://github.com/LuckyDams/Attr-Dict" }, "release_url": "https://pypi.org/project/Attr-Dict/1.0.0/", "requires_dist": null, "requires_python": "", "summary": "Yet another Attribute Dict implementation !", "version": "1.0.0" }, "last_serial": 5090998, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "e5c8573688db451e339550fd15f208aa", "sha256": "6fcb77fb2dc9336a2a34357810ba2ea964cbeb28dafc070975cb75c5844f1cc6" }, "downloads": -1, "filename": "Attr_Dict-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "e5c8573688db451e339550fd15f208aa", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6281, "upload_time": "2019-04-03T13:49:06", "url": "https://files.pythonhosted.org/packages/06/38/431d442ceb2a25d2732b98ecb272875d8639e9a48f8569afe5c2ec76861b/Attr_Dict-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f611c82336b5ebbff99e68f641992bcf", "sha256": "3378d2e5a329fc084840c8644cd3759764016ec2f9e0d7cd4307f1a909597f4e" }, "downloads": -1, "filename": "Attr-Dict-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f611c82336b5ebbff99e68f641992bcf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4640, "upload_time": "2019-04-03T13:49:08", "url": "https://files.pythonhosted.org/packages/62/54/0e75a87fe1449052e6ed5740fedeeda2cd0adba0305a3a0fe9ccc707174b/Attr-Dict-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e5c8573688db451e339550fd15f208aa", "sha256": "6fcb77fb2dc9336a2a34357810ba2ea964cbeb28dafc070975cb75c5844f1cc6" }, "downloads": -1, "filename": "Attr_Dict-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "e5c8573688db451e339550fd15f208aa", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 6281, "upload_time": "2019-04-03T13:49:06", "url": "https://files.pythonhosted.org/packages/06/38/431d442ceb2a25d2732b98ecb272875d8639e9a48f8569afe5c2ec76861b/Attr_Dict-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f611c82336b5ebbff99e68f641992bcf", "sha256": "3378d2e5a329fc084840c8644cd3759764016ec2f9e0d7cd4307f1a909597f4e" }, "downloads": -1, "filename": "Attr-Dict-1.0.0.tar.gz", "has_sig": false, "md5_digest": "f611c82336b5ebbff99e68f641992bcf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4640, "upload_time": "2019-04-03T13:49:08", "url": "https://files.pythonhosted.org/packages/62/54/0e75a87fe1449052e6ed5740fedeeda2cd0adba0305a3a0fe9ccc707174b/Attr-Dict-1.0.0.tar.gz" } ] }