# Collections


# DotDict

class

prefect.utilities.collections.DotDict

(init_dict=None, **kwargs)[source]

A dict that also supports attribute ("dot") access. Think of this as an extension to the standard python dict object. Note: while any hashable object can be added to a DotDict, only valid Python identifiers can be accessed with the dot syntax; this excludes strings which begin in numbers, special characters, or double underscores.

Args:

  • init_dict (dict, optional): dictionary to initialize the DotDict with
  • **kwargs (optional): key, value pairs with which to initialize the DotDict
Example:

    dotdict = DotDict({'a': 34}, b=56, c=set())
    dotdict.a # 34
    dotdict['b'] # 56
    dotdict.c # set()

methods:                                                                                                                                                       

prefect.utilities.collections.DotDict.copy

()[source]

Creates and returns a shallow copy of the current DotDict

prefect.utilities.collections.DotDict.get

(key, default=None)[source]

This method is defined for MyPy, which otherwise tries to type the inherited .get() method incorrectly.

Args:

  • key (str): the key to retrieve
  • default (Any): a default value to return if the key is not found
Returns:
  • Any: the value of the key, or the default value if the key is not found

prefect.utilities.collections.DotDict.to_dict

()[source]

Converts current DotDict (and any DotDicts contained within) to an appropriate nested dictionary.



# Functions

top-level functions:                                                                                                                                                       

prefect.utilities.collections.merge_dicts

(d1, d2)[source]

Updates d1 from d2 by replacing each (k, v1) pair in d1 with the corresponding (k, v2) pair in d2.

If the value of each pair is itself a dict, then the value is updated recursively.

Args:

  • d1 (MutableMapping): A dictionary to be replaced
  • d2 (MutableMapping): A dictionary used for replacement
Returns:
  • A MutableMapping with the two dictionary contents merged

prefect.utilities.collections.as_nested_dict

(obj, dct_class=<class 'prefect.utilities.collections.DotDict'>)[source]

Given a obj formatted as a dictionary, transforms it (and any nested dictionaries) into the provided dct_class

Args:

  • obj (Any): An object that is formatted as a dict
  • dct_class (type): the dict class to use (defaults to DotDict)
Returns:
  • A dict_class representation of the object passed in

prefect.utilities.collections.dict_to_flatdict

(dct, parent=None)[source]

Converts a (nested) dictionary to a flattened representation.

Each key of the flat dict will be a CompoundKey tuple containing the "chain of keys" for the corresponding value.

Args:

  • dct (dict): The dictionary to flatten
  • parent (CompoundKey, optional): Defaults to None. The parent key (you shouldn't need to set this)
Returns:
  • dict: A flattened dict

prefect.utilities.collections.flatdict_to_dict

(dct, dct_class=None)[source]

Converts a flattened dictionary back to a nested dictionary.

Args:

  • dct (dict): The dictionary to be nested. Each key should be a CompoundKey, as generated by dict_to_flatdict()
  • dct_class (type, optional): the type of the result; defaults to dict
Returns:
  • D: An instance of dct_class used to represent a nested dictionary, bounded as a MutableMapping or dict

This documentation was auto-generated from commit bd9182e
on July 31, 2024 at 18:02 UTC