ocebuild.parsers.dict#

Dictionary helper functions.

Module Contents#

Functions#

flatten_dict(→ Dict[str, any])

Flattens a dictionary.

nested_get(→ Union[dict, any, None])

Retrieves a nested value from a dictionary.

nested_set(→ None)

Sets a nested value in a dictionary.

nested_del(→ None)

Deletes a nested value in a dictionary.

merge_dict(→ dict)

Merges two dictionaries recursively.

ocebuild.parsers.dict.flatten_dict(dic: dict, delimiter: str = '.') Dict[str, any][source]#

Flattens a dictionary.

Parameters:
  • dic – The dictionary to flatten.

  • delimiter (optional) – custom key delimiter.

Returns:

A flattened dictionary

ocebuild.parsers.dict.nested_get(dic: dict, keys: List[str], default: any | None = None) dict | any | None[source]#

Retrieves a nested value from a dictionary.

Parameters:
  • dic – The dictionary to retrieve the value from.

  • keys – The keys to traverse the dictionary.

Returns:

The value at the end of the keys list.

ocebuild.parsers.dict.nested_set(dic: dict, keys: List[str], value: any) None[source]#

Sets a nested value in a dictionary.

Parameters:
  • dic – The dictionary to set the value in.

  • keys – The keys to traverse the dictionary.

  • value – The value to set.

ocebuild.parsers.dict.nested_del(dic: dict, keys: List[str]) None[source]#

Deletes a nested value in a dictionary.

Parameters:
  • dic – The dictionary to delete the value from.

  • keys – The keys to traverse the dictionary.

ocebuild.parsers.dict.merge_dict(a: dict, b: dict) dict[source]#

Merges two dictionaries recursively.

Parameters:
  • a – The first dictionary.

  • b – The second dictionary.

Returns:

The merged dictionary.