def flatten_dict(a_dict, parent_keys=None, current_parent_key=None):
    """Given a dict as input, return a version of the dict where the keys
    are no longer nested, and instead flattened.
    EG:
        >>> flatten_dict({"a": {"b": 1}})
        {"a.b": 1}

    NB: The kwargs are only for internal use of the function and should not be
    used by the caller.
    """

    if parent_keys is None:
        parent_keys = []

    for key, value in a_dict.items():
        if current_parent_key:
            key = "%s.%s" % (current_parent_key, key)
        if isinstance(value, dict):
            flatten_dict(value, parent_keys=parent_keys, current_parent_key=key)
        else:
            parent_keys.append((key, value))

    return dict(parent_keys)