def _object_to_dict(obj):
    """
    Recursively get the attributes
    of an object as a dictionary.

    :param obj: Object whose attributes are to be extracted.
    :returns: A dictionary or the object.
    """
    # https://stackoverflow.com/a/71366813/7175713
    data = {}
    if getattr(obj, "__dict__", None):
        for key, value in obj.__dict__.items():
            data[key] = _object_to_dict(value)
        return data
    return obj