import base64


def base64_encode(data):
    """
    base64 encode data, will convert given strings to bytes.
    Returns base64 encoded string.
    """
    if type(data) == str:
        data = str.encode(data)
    return base64.encodebytes(data).decode('utf-8')