Skip to main content

Dictionary with loose rules for finding keys.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

permissive-dict-1.0.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

permissive_dict-1.0.3-py2.py3-none-any.whl (5.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file permissive-dict-1.0.3.tar.gz.

File metadata

  • Download URL: permissive-dict-1.0.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

File hashes

Hashes for permissive-dict-1.0.3.tar.gz
Algorithm Hash digest
SHA256 50605e3d9a061291505918c0ae2a64e555bd9a9fc92790be286766daee87db82
MD5 a5007e0c6c8a73dc7bf29eeb47ff4362
BLAKE2b-256 b87621336d373d268385c2b380cdf1ed259bdf01635b6fef970a42e038a1a807

See more details on using hashes here.

File details

Details for the file permissive_dict-1.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: permissive_dict-1.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.41.0 CPython/3.8.0

File hashes

Hashes for permissive_dict-1.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 34c6d584d4437a8c76904a37241f00a53c81b5d47903ffa195c3b47d4e12d827
MD5 db43de3ab736097db1f3fdef87a68d92
BLAKE2b-256 e171b7ec95781a6532d5cf9fa5b55bfa801e186a4c2e7cde682c78a1abe5805e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page