def _safe_attr(self, attr):
        """Convert a key into something that is accessible as an attribute"""
        allowed = string.ascii_letters + string.digits + '_'

        if isinstance(attr, tuple):
            attr = "_".join([str(x) for x in attr])

        attr = attr.decode('utf-8', 'ignore') if isinstance(attr, bytes) else str(attr)
        if self.__box_config()['camel_killer_box']:
            attr = _camel_killer(attr)

        out = []
        last_safe = 0
        for i, character in enumerate(attr):
            if character in allowed:
                last_safe = i
                out.append(character)
            elif not out:
                continue
            else:
                if last_safe == i - 1:
                    out.append('_')

        out = "".join(out)[:last_safe + 1]

        try:
            int(out[0])
        except (ValueError, IndexError):
            pass
        else:
            out = f'{self.__box_config()["box_safe_prefix"]}{out}'

        if out in kwlist:
            out = f'{self.__box_config()["box_safe_prefix"]}{out}'

        return out
Convert a key into something that is accessible as an attribute
dynaconf/vendor/box/box.py