Skip to content

Custom Types

drizm_commons.utils.type

Custom data-type implementations.

from drizm_commons.utils.type import *

AttrDict

A dictionary whose keys can be accessed like attributes.

Examples:

obj = AttrDict({
    "test": "ok",
    "something-else": 3
})
obj.test  # "ok"
obj.something_else  # 3
getattr(obj, "something-else")  # AttributeError

IterableKeyDictionary

A dictionary that supports a list or tuple of scalar, hashable values as keys.

Also has support for normal hashable keys.

Examples:

obj = IterableKeyDictionary({
    ("order", 66): "yes my lord"
})
obj["order"]  # "yes my lord"
obj[66]  # "yes my lord"
obj[("order", 66)]  # "yes my lord"