{ "info": { "author": "Brandon Gillespie", "author_email": "bjg-pypi@cold.org", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: GNU Affero General Public License v3", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "Dictlib is a lightweight add-on for dictionaries, featuring:\n\n * *Dictionary union* done properly: `union()` (not immutably safe), `union_copy()` (immutably safe)\n * *`\"String.dot\"` notation for retrieval* from classic dictionaries, with a string key: `dig()`, `dig_get()`, `dug()`. For efficiencies sake, it isn't an object. If you want dot notation more commonly used in your code, use `Dict()` instead.\n * *`Object.key` Dictionary keys as object attributes* (easy classes): `Dict()` (useful for rapid prototyping,\n just define your class as a Dict, either way:\n * balancing features with performance: we could do more (such as supporting dictionary['this.key'] inline dot notation), but I wanted to \n keep it near native performance, and having an external function like `dig()` is similar to Ruby's method, so you can use it as needed,\n and if you really want dot notation, use an inline method that is efficient at runtime like `Dict()`\n\n```python\nNewClass = Dict\nclass NewClass(Dict):\n pass\n```\n\nIf this doesn't work for you, consider other dictionary helper libraries:\n\n * [Scalpl](https://github.com/ducdetronquito/scalpl)\n - a more indepth tool that does similar to `dictlib.dig()` and `dictlib.dug()`\n - does not include keys as object attributes -- `Dict()`\n * [Addict](https://github.com/mewwts/addict) \n - similar to `addict.Dict()` and `dictlib.Dict()`\n - As time allows I'll add a better comparison\n * [Box](https://github.com/cdgriffith/Box )\n - similar to `addict.Dict()` and `dictlib.Dict()`\n - As time allows I'll add a better comparison\n\nunion() and union_copy()\n===============\n\n```python\nfrom dictlib import union, union_copy\ndict1 = union(dict1, dict2)\ndict3 = union_copy(dict1, dict2)\n```\n\nDeep union of dict2 into dict1, where dictionary values are recursively merged.\nNon-dictionary elements are replaced, with preference given to dict2.\n\nThis alters dict1, which is the returned result, but it will have references to\nboth dictionaries. If you do not want this, use union_copy(), which is less\nefficient but data-safe.\n\ndig() and dig_get()\n=============\n\nRecursively pull from a dictionary, using dot notation. dig_get behaves like `dict.get()`, but with dot-notated keys.\n\n```python\nfrom dictlib import dig, dig_get\ndict1 = {\"a\":{\"b\":{\"c\":1},\"d\":[{\"e\":1},{\"f\":2}]}}\ndig(dict1, \"a.b.c\")\n# 1\n\ndig(dict1, \"a.d[1].f\")\n# 2\n\ndig(dict1, \"a.b.z\")\n# KeyError: 'z'\n\ndig_get(dict1, \"a.b.z\")\n# None\n\ndig_get(dict1, \"a.b.z\", 2)\n# 2\n```\n\ndug()\n=============\n\nInverse of `dig()`, `dug()` puts an item into a nested dictionary, using dot notation.\nThis does not behave immutably, as it alters the origin dictionary. \n\n```python\nfrom dictlib import dug\ndict1 = {\"a\":{\"b\":{\"c\":1}}}\ndug(dict1, \"a.b.c\", 200)\n# {'a': {'b': {'c': 200}}}\n\n# and it will instantiate dictionaries as values if the key doesn't exist:\ndug(dict1, \"a.b.z.e\", True)\n# {'a': {'b': {'c': 200, 'z': {'e': True}}}}\n```\n\nNote: dug() does not support pushing to lists within a dictionary, it assumes\nall values are dictionaries in your dot notation string. If you attempt to use\na list index, it still behaves as if it were a dictionary, which may give you\nunexpected results:\n\n```python\ndict1 = {\"a\":{\"b\":{\"c\":1}}}\ndug(dict1, \"a.b.d[0].e\", True)\n# {'a': {'b': {'c': 1, 'd': {0: {'e': True}}}}}\n```\n\n(PR's to finish this feature correctly are appreciated)\n\nDict()\n=============\n\nA bit of sugar to represent a dictionary in object form where keys are set as\nattributes on the object. Features:\n\n* it tokenizes your keys if they are not python safe (`\"this-key\"` is `.this_key`). Example:\n```python\nd = Dict({\"this key\": \"value\"})\nd[\"this-key\"]\n# \"value\"\nd.this_key\n# \"value\"\n```\n* Recursive -- it will walk the full depth of the dictionary\n\nThis is not python zen because it provides an alternate way to use dictionaries,\nand it has some challenges with names that collide with builtin methods, but it\nis very\n\nBut I'm okay with this, because it is handy bit of sugar.\n\nLimitations:\n\n* raises error if there is a name conflict with reserved words\n* reserves the key prefix \\f$\\f for internal use (raises error)\n* because of namespace conflict problems, you must be cautious on what keys are input\n* Two keys exist for each non-tokenized name, such as `ugly var!`,\n which is tokenized to `ugly_var_`. However, they do not point to the same\n data value! While both exist, if exporting to original object *only* the\n value of the tokenized name is used (see examples)\n\n```python\nfrom dictlib import Dict\nDict(key1=1, a=2)\n# {'key1': 1, 'a': 2}\n\ntest_dict = {\"a\":{\"b\":1,\"ugly var!\":2}, \"c\":3}\ntest_obj = Dict(**test_dict)\ntest_obj.keys()\n# ['a', 'c']\n\n'a' in test_obj\n# True\ntest_obj.get('c')\n# 3\ntest_obj['c']\n# 3\ntest_obj.c\n# 3\ntest_obj.c = 4\ntest_obj.c\n# 4\ntest_obj.a.b\n# 1\ntest_obj.a.ugly_var_\n# 2\ntest_obj.a['ugly var!']\n# 2\n\n# however, these are distinctly different values, don't be confused:\ntest_obj.a.ugly_var_ = 0xdeadbeef\ntest_obj.a.ugly_var_\n# 3735928559\ntest_obj.a['ugly var!']\n# 2\n\n# how it looks -- in most cases it tries to look normal for you, but you can\n# use __export__ and __original__ to be assured. In some cases you can see the\n# mapping keys, which is confusing, and needs to be fixed (PR appreciated):\ntest_obj = Dict(test_dict)\ntest_obj\n# {'a': {'b': 1, 'ugly_var_': 2, 'ugly var!': 2}, 'c': 3}\nimport json\njson.dumps(test_obj)\n# '{\"a\": {\"b\": 1, \"ugly_var_\": 2, \"\\\\f$\\\\fugly_var_\": \"ugly var!\", \"ugly var!\": 2}, \"c\": 3}'\n\njson.dumps(test_obj.__export__()) # removes key mapping values, but keeps split tokenized keys\n# '{\"a\": {\"b\": 1, \"ugly_var_\": 2, \"ugly var!\": 2}, \"c\": 3}'\n\njson.dumps(test_obj.__original__()) # removes key mapping values and tokenized keys\n# '{\"a\": {\"b\": 1, \"ugly var!\": 2}, \"c\": 3}'\n\ntest_obj.__original__()\n# {'a': {'b': 1, 'ugly var!': 2}, 'c': 3}\n```\n\nNote: `Dict()` was previously `Obj()`, which has been deprecated but is still supported.\n\ndictlib.original() and dictlib.export()\n======\n\nWalk `dict1` which may be mixed dict()/Dict() and export any Dict()'s to dict(),\nusing the `Dict.__original__()` or `Dict.__export__()` method, respectively.\n\n(useful for data conversions, such as with dict->yaml)\n```python\nimport json\nexport(Dict({\"ugly first\": 1, \"second\": {\"tres\": Dict({\"nachos\":2})}}))\n# {'ugly_first': 1, 'ugly first': 1, 'second': {'tres': {'nachos': 2}}}\n\njson.dumps(Dict({\"ugly first\": 1, \"second\": {\"tres\": Dict({\"nachos\":2})}}))\n# '{\"ugly_first\": 1, \"\\\\\\\\f$\\\\\\\\fugly_first\": \"ugly first\", \"ugly first\": 1, \"second\": {\"tres\": {\"nachos\": 2}}}'\n\njson.dumps(export(Dict({\"ugly first\": 1, \"second\": {\"tres\": Dict({\"nachos\":2})}})))\n# '{\"ugly_first\": 1, \"ugly first\": 1, \"second\": {\"tres\": {\"nachos\": 2}}}'\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/srevenant/dictlib", "keywords": "dict,union,object,dig,dug", "license": "", "maintainer": "", "maintainer_email": "", "name": "dictlib", "package_url": "https://pypi.org/project/dictlib/", "platform": "", "project_url": "https://pypi.org/project/dictlib/", "project_urls": { "Homepage": "https://github.com/srevenant/dictlib" }, "release_url": "https://pypi.org/project/dictlib/1.1.5/", "requires_dist": null, "requires_python": "", "summary": "Dictionary Library including good deep merge and dictionary as objects", "version": "1.1.5" }, "last_serial": 5684729, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "5adc24f0deff327977c6e8afe5b8ae6b", "sha256": "699bb6873abe1af1b93394c07228b339fd9093bfa5e6e8a8d123ddd54dcdee7e" }, "downloads": -1, "filename": "dictlib-1.0.tar.gz", "has_sig": false, "md5_digest": "5adc24f0deff327977c6e8afe5b8ae6b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3721, "upload_time": "2016-07-02T17:59:39", "url": "https://files.pythonhosted.org/packages/5f/16/6b9c485cb57f55e5781b7473f245561ea11c03a75d146d5c495ab7abda93/dictlib-1.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "60e079593a419e2acdbba632bcbad9a0", "sha256": "8fb4bc367805cc6fc5b3a0de1a168f59974d308b5ff2c83792784eaee65cb841" }, "downloads": -1, "filename": "dictlib-1.0.1.tar.gz", "has_sig": false, "md5_digest": "60e079593a419e2acdbba632bcbad9a0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3868, "upload_time": "2017-12-11T20:04:54", "url": "https://files.pythonhosted.org/packages/e4/bd/01aa9b24cfc05e414f5af4e7e509787292194cb8abd1fc841acebd6b138b/dictlib-1.0.1.tar.gz" } ], "1.0.2": [ { "comment_text": "", "digests": { "md5": "0e64107077b065d4f95129b23b82ac12", "sha256": "30288fe5eb9e5eb96135904f64d56bbe2ae4a30a6ad5b2881b093cb1522fbf38" }, "downloads": -1, "filename": "dictlib-1.0.2.tar.gz", "has_sig": false, "md5_digest": "0e64107077b065d4f95129b23b82ac12", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3880, "upload_time": "2017-12-11T20:08:28", "url": "https://files.pythonhosted.org/packages/97/b1/e49a46329f0cc4ed4350cb748a86d344fa0845b8ce97bc45657196073912/dictlib-1.0.2.tar.gz" } ], "1.0.3": [ { "comment_text": "", "digests": { "md5": "1f9ca40ec5911208a19e36b8a46133bb", "sha256": "00dce2a34471518da8987c154ca600015ae64e53ce872da7f1d7b1eca35db39e" }, "downloads": -1, "filename": "dictlib-1.0.3.tar.gz", "has_sig": false, "md5_digest": "1f9ca40ec5911208a19e36b8a46133bb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4339, "upload_time": "2017-12-18T20:27:06", "url": "https://files.pythonhosted.org/packages/f1/60/bc6e6122a34f74ce9864fb63384460bced174aee569b09481f96f206bffc/dictlib-1.0.3.tar.gz" } ], "1.0.4": [ { "comment_text": "", "digests": { "md5": "d67bb4a3999cba738337f9f6c00cde4e", "sha256": "737cf9e29bb3867753993f05d38d41af643a992207b108f56a0a230ac3223d03" }, "downloads": -1, "filename": "dictlib-1.0.4.tar.gz", "has_sig": false, "md5_digest": "d67bb4a3999cba738337f9f6c00cde4e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4600, "upload_time": "2018-01-31T14:59:15", "url": "https://files.pythonhosted.org/packages/13/f6/eefb0f73fd8d14aeaed191180109d39c91ad1e5987ccd39711ba7f735601/dictlib-1.0.4.tar.gz" } ], "1.0.6": [ { "comment_text": "", "digests": { "md5": "6fbbbe9b29e48b3ce7e3242eb0403867", "sha256": "6cfd15b5c56110d5b12ac50d9020334e3df718b746e8a77abab65c4750efdb81" }, "downloads": -1, "filename": "dictlib-1.0.6.tar.gz", "has_sig": false, "md5_digest": "6fbbbe9b29e48b3ce7e3242eb0403867", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4609, "upload_time": "2018-01-31T20:08:42", "url": "https://files.pythonhosted.org/packages/57/43/eeb15383304d3febda53d9aa4895a6a9ce559bd1d3a0bc4e28653752710d/dictlib-1.0.6.tar.gz" } ], "1.1.2": [ { "comment_text": "", "digests": { "md5": "d025dbdecc638d53d21800c9bc9e99d8", "sha256": "6db94be9bbd80602ad32afb1507543275c973c05bebf69f1236c8a73506b0b5e" }, "downloads": -1, "filename": "dictlib-1.1.2-py3-none-any.whl", "has_sig": false, "md5_digest": "d025dbdecc638d53d21800c9bc9e99d8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 18283, "upload_time": "2018-10-01T00:31:59", "url": "https://files.pythonhosted.org/packages/b6/e4/c66681aa95fffe77a0e8c211523c3ff25bed371eaac6e23a897d66a05987/dictlib-1.1.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ef70b6e6e77525ea9982817588e988b6", "sha256": "7945a38c37d137cc2a854b3bc803a53f8b3b9c32478caf534c64ffc020416742" }, "downloads": -1, "filename": "dictlib-1.1.2.tar.gz", "has_sig": false, "md5_digest": "ef70b6e6e77525ea9982817588e988b6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5741, "upload_time": "2018-10-01T00:32:00", "url": "https://files.pythonhosted.org/packages/a5/b1/cc6991ea90fea352170213529f2aa245b4b6443f58ad048de593c5430073/dictlib-1.1.2.tar.gz" } ], "1.1.3": [ { "comment_text": "", "digests": { "md5": "cd01b28ec04ce256828ac647389411cf", "sha256": "39ac3c5d02088a7978d330328450e616f207cf3afe24e055bff4a4ad67c3f89d" }, "downloads": -1, "filename": "dictlib-1.1.3.tar.gz", "has_sig": false, "md5_digest": "cd01b28ec04ce256828ac647389411cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5988, "upload_time": "2019-07-28T19:25:10", "url": "https://files.pythonhosted.org/packages/00/0a/b2a48211353bfd1c57f0a7ef29f712f8b364f0db9ba4be8f9d5d4a21649c/dictlib-1.1.3.tar.gz" } ], "1.1.5": [ { "comment_text": "", "digests": { "md5": "7f5a31506dd94da30cd5ca8a40f502c8", "sha256": "6d4ca929eb21f3de11b391691949e474801e468db16d5b2967f6357015eafb92" }, "downloads": -1, "filename": "dictlib-1.1.5-py3-none-any.whl", "has_sig": false, "md5_digest": "7f5a31506dd94da30cd5ca8a40f502c8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20400, "upload_time": "2019-08-15T23:11:09", "url": "https://files.pythonhosted.org/packages/9a/5f/96afc85c774e92e70172e93812ac15f76c823bd8015a79c99f318778f18a/dictlib-1.1.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8902351db872c3c47d87de78d3b70ffe", "sha256": "6aec0b3f1eb742497c14a181f673a976a0981e67210ee955b3e417a4e7d3c22f" }, "downloads": -1, "filename": "dictlib-1.1.5.tar.gz", "has_sig": false, "md5_digest": "8902351db872c3c47d87de78d3b70ffe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9114, "upload_time": "2019-08-15T23:11:11", "url": "https://files.pythonhosted.org/packages/1e/00/7da5259b2ee9ae2ee17c96bb8aa5af14cc69fe4907a44bbf6bec3ce6f3cd/dictlib-1.1.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7f5a31506dd94da30cd5ca8a40f502c8", "sha256": "6d4ca929eb21f3de11b391691949e474801e468db16d5b2967f6357015eafb92" }, "downloads": -1, "filename": "dictlib-1.1.5-py3-none-any.whl", "has_sig": false, "md5_digest": "7f5a31506dd94da30cd5ca8a40f502c8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 20400, "upload_time": "2019-08-15T23:11:09", "url": "https://files.pythonhosted.org/packages/9a/5f/96afc85c774e92e70172e93812ac15f76c823bd8015a79c99f318778f18a/dictlib-1.1.5-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8902351db872c3c47d87de78d3b70ffe", "sha256": "6aec0b3f1eb742497c14a181f673a976a0981e67210ee955b3e417a4e7d3c22f" }, "downloads": -1, "filename": "dictlib-1.1.5.tar.gz", "has_sig": false, "md5_digest": "8902351db872c3c47d87de78d3b70ffe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9114, "upload_time": "2019-08-15T23:11:11", "url": "https://files.pythonhosted.org/packages/1e/00/7da5259b2ee9ae2ee17c96bb8aa5af14cc69fe4907a44bbf6bec3ce6f3cd/dictlib-1.1.5.tar.gz" } ] }