Public API

See also

Check out Examples derived from real and fully tested source code.

dotty_dict.dotty_dict.dotty(dictionary=None)[source]

Factory function for Dotty class.

Create Dotty wrapper around existing or new dictionary.

Parameters:dictionary (dict) – Any dictionary or dict-like object
Returns:Dotty instance
class dotty_dict.dotty_dict.Dotty(dictionary, separator, esc_char, list_embedded=False)[source]

Dictionary and dict-like objects wrapper.

Dotty wraps dictionary and provides proxy for quick accessing to deeply nested keys and values using dot notation.

Dot notation can be customize in special cases. Let’s say dot character has special meaning, and you want to use other character for accessing deep keys.

Dotty does not copy original dictionary but it operates on it. All changes made in original dictionary are reflected in dotty wrapped dict and vice versa.

Parameters:
  • dictionary (dict) – Any dictionary or dict-like object
  • separator (str) – Character used to chain deep access.
  • esc_char (str) – Escape character for separator.
  • list_embedded (bool) – If set to True all numeric keys will be converted to indexes
clear()

Removes all elements from dotty dict.

items()

Returns generator of dotty dict’s (key, value) tuple pairs.

keys()

Returns generator of dotty dict’s keys.

values()

Returns generator of dotty dict’s values.

update(dict2)

Adds dictionary dict2’s key-values pairs to dotty dict.

copy()[source]

Returns a shallow copy of dictionary wrapped in Dotty.

Returns:Dotty instance
static fromkeys(seq, value=None)[source]

Create a new dictionary with keys from seq and values set to value.

New created dictionary is wrapped in Dotty.

Parameters:
  • seq – Sequence of elements which is to be used as keys for the new dictionary
  • value – Value which is set to each element of the dictionary
Returns:

Dotty instance

get(key, default=None)[source]

Get value from deep key or default if key does not exist.

This method match 1:1 with dict .get method except that it accepts deeply nested key with dot notation.

Parameters:
  • key (str) – Single key or chain of keys
  • default (Any) – Default value if deep key does not exist
Returns:

Any or default value

pop(key, default=None)[source]

Pop key from Dotty.

This method match 1:1 with dict .pop method except that it accepts deeply nested key with dot notation.

Parameters:
  • key (str) – Single key or chain of keys
  • default (Any) – If default is provided will be returned
Raises:

KeyError – If key does not exist and default has not been provided

Returns:

Any or default value

setdefault(key, default=None)[source]

Get key value if exist otherwise set default value under given key and return its value.

This method match 1:1 with dict .setdefault method except that it accepts deeply nested key with dot notation.

Parameters:
  • key (str) – Single key or chain of keys
  • default (Any) – Default value for not existing key
Returns:

Value under given key or default

to_dict()[source]

Return wrapped dictionary.

This method does not copy wrapped dictionary.

Return dict:Wrapped dictionary