import codecs


def to_json(python_object: bytes) -> dict:
    """ Custom serialization for cookie

    Base64 encode cookie before storing the config as settings_file

    Arguments:
            python_object: Python serialized object

    Returns:
            dict
    """
    if isinstance(python_object, bytes):
        return {
            "__class__": "bytes",
            "__value__": codecs.encode(python_object, "base64").decode(),
        }

    raise TypeError(repr(python_object) + " is not JSON serializable")