permissive-dict


Namepermissive-dict JSON
Version 1.0.4 PyPI version JSON
download
home_pagehttps://github.com/Martlark/PermissiveDict
SummaryDictionary with loose rules for finding keys.
upload_time2021-05-06 06:34:47
maintainer
docs_urlNone
authorAndrew Rowe
requires_python
licenseApache Software License
keywords dictionary dict
VCS
bugtrack_url
requirements setuptools wheel twine
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # PermissiveDict

Dictionary class with loose rules for returning an attribute or a requested key value.  
--------------------------------------------------------------------------------------

Note: may resort to iterating the dict values to find the matching requested key, so is potentially slow.

Key is first directly found using the exact key, and then loose rules are used.

Installing
----------

    pip install permissive-dict

Key Search Rules:
-----------------

1. Keys compared without regard to case.
2. Spaces, underscores, full-stops and dashes are equivalent in a requested key.
3. Requested key is converted to str and stripped for wild card searching.
4. Items in the list can be retrieved by, get, attribute_access, call or array requested_key.
5. First matching element is returned.
6. Default of '' is used instead of dict standard None or raising KeyError
7. Multiple keys can be supplied separated with , (comma)

Example:

        from permissive_dict import PermissiveDict

        a = PermissiveDict({'A B': 2, 4: 4})
        a.get('A_b') == a['a_b'] == a['A b'] == a['A_B'] == a['a-b '] == a['a.b '] == a.a_b == a.A_b == a('a-b')

        a.get('blue,4') == 4

        a.get('4') == a[4] == a(4) == a('4')

Items with multiple wildcard keys matching in the dictionary will return the first item found.

Keys can be accessed as attributes, array index, get() or by calling the instance variable.

Key and value can be set as an attribute.
-----------------------------------------

Example:

    a = PermissiveDict()
    a.hello = 4
    a.hello == a['hello'] == a('hello') == a.get('HellO')

Converting an entire list of dicts
----------------------------------

An entire list of dictionaries can be converted to PermissiveDict using
the `convert_list` method.  NOTE: no deep conversion is done and child 
dictionaries are not converted.

Example:

    list_of_dicts = [dict(a=n) for n in range(10)]
    permissive_list = PermissiveDict.convert_list(list_of_dicts)

Notes
-----

Only Python 3 is supported.

Release history
---------------
1.0.4 Fix missing handling of _ and -



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Martlark/PermissiveDict",
    "name": "permissive-dict",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "dictionary dict",
    "author": "Andrew Rowe",
    "author_email": "rowe.andrew.d@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f8/c4/928bccb0e7bacc06a0f5b9216ee790f231025d2bc0ab50f034598ca33d35/permissive-dict-1.0.4.tar.gz",
    "platform": "",
    "description": "# PermissiveDict\n\nDictionary class with loose rules for returning an attribute or a requested key value.  \n--------------------------------------------------------------------------------------\n\nNote: may resort to iterating the dict values to find the matching requested key, so is potentially slow.\n\nKey is first directly found using the exact key, and then loose rules are used.\n\nInstalling\n----------\n\n    pip install permissive-dict\n\nKey Search Rules:\n-----------------\n\n1. Keys compared without regard to case.\n2. Spaces, underscores, full-stops and dashes are equivalent in a requested key.\n3. Requested key is converted to str and stripped for wild card searching.\n4. Items in the list can be retrieved by, get, attribute_access, call or array requested_key.\n5. First matching element is returned.\n6. Default of '' is used instead of dict standard None or raising KeyError\n7. Multiple keys can be supplied separated with , (comma)\n\nExample:\n\n        from permissive_dict import PermissiveDict\n\n        a = PermissiveDict({'A B': 2, 4: 4})\n        a.get('A_b') == a['a_b'] == a['A b'] == a['A_B'] == a['a-b '] == a['a.b '] == a.a_b == a.A_b == a('a-b')\n\n        a.get('blue,4') == 4\n\n        a.get('4') == a[4] == a(4) == a('4')\n\nItems with multiple wildcard keys matching in the dictionary will return the first item found.\n\nKeys can be accessed as attributes, array index, get() or by calling the instance variable.\n\nKey and value can be set as an attribute.\n-----------------------------------------\n\nExample:\n\n    a = PermissiveDict()\n    a.hello = 4\n    a.hello == a['hello'] == a('hello') == a.get('HellO')\n\nConverting an entire list of dicts\n----------------------------------\n\nAn entire list of dictionaries can be converted to PermissiveDict using\nthe `convert_list` method.  NOTE: no deep conversion is done and child \ndictionaries are not converted.\n\nExample:\n\n    list_of_dicts = [dict(a=n) for n in range(10)]\n    permissive_list = PermissiveDict.convert_list(list_of_dicts)\n\nNotes\n-----\n\nOnly Python 3 is supported.\n\nRelease history\n---------------\n1.0.4 Fix missing handling of _ and -\n\n\n",
    "bugtrack_url": null,
    "license": "Apache Software License",
    "summary": "Dictionary with loose rules for finding keys.",
    "version": "1.0.4",
    "project_urls": {
        "Download": "https://github.com/Martlark/PermissiveDict/archive/1.0.4.tar.gz",
        "Homepage": "https://github.com/Martlark/PermissiveDict"
    },
    "split_keywords": [
        "dictionary",
        "dict"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "213b03b0f92f754515166c74f0327fa72861ba143790baa72bc120adef60f250",
                "md5": "89858a5fe13389b16529101b5c0d176b",
                "sha256": "6a0d0330be7bf6a496310d8c07eb3bd3aa1a782b7322b1393a912e7ae364e508"
            },
            "downloads": -1,
            "filename": "permissive_dict-1.0.4-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "89858a5fe13389b16529101b5c0d176b",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 5115,
            "upload_time": "2021-05-06T06:34:45",
            "upload_time_iso_8601": "2021-05-06T06:34:45.308551Z",
            "url": "https://files.pythonhosted.org/packages/21/3b/03b0f92f754515166c74f0327fa72861ba143790baa72bc120adef60f250/permissive_dict-1.0.4-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f8c4928bccb0e7bacc06a0f5b9216ee790f231025d2bc0ab50f034598ca33d35",
                "md5": "6ec71fd081b4cca96263cad850fedfc0",
                "sha256": "5b274b982c9dbcb058e9a665b752c9cee4bf4a4d957762ee528daad1eb009a8d"
            },
            "downloads": -1,
            "filename": "permissive-dict-1.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "6ec71fd081b4cca96263cad850fedfc0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4432,
            "upload_time": "2021-05-06T06:34:47",
            "upload_time_iso_8601": "2021-05-06T06:34:47.655747Z",
            "url": "https://files.pythonhosted.org/packages/f8/c4/928bccb0e7bacc06a0f5b9216ee790f231025d2bc0ab50f034598ca33d35/permissive-dict-1.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-06 06:34:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Martlark",
    "github_project": "PermissiveDict",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "setuptools",
            "specs": []
        },
        {
            "name": "wheel",
            "specs": []
        },
        {
            "name": "twine",
            "specs": []
        }
    ],
    "tox": true,
    "lcname": "permissive-dict"
}
        
Elapsed time: 0.41226s