simdb.database.models.utils module

simdb.database.models.utils.checked_get(data: dict[str, Any], key, expected_type: type, optional: bool = False)[source]
simdb.database.models.utils.flatten_dict(data: dict[str, Any], prefix: str = '', delim: str = '.') dict[str, Any][source]

Recursively flattens a nested dictionary, representing nested structures with keys delimited by a string, and lists with index suffixes.

Example:
>>> flatten_dict({"a": {"b": 1}, "c": [2, {"d": 3}]})
{'a.b': 1, 'c#1': 2, 'c#2.d': 3}
Parameters:
data: dict[str, Any]

The nested dictionary to flatten.

prefix: str = ''

The prefix to prepend to keys.

delim: str = '.'

The delimiter string to separate keys.

Returns:

A flat dictionary.

simdb.database.models.utils.unflatten_dict(in_dict: dict[str, Any]) dict[str, dict | Any][source]