import base64


def b64encode(data: str, urlsafe: bool = False) -> str:
    """Accepts a string and returns the Base64 encoded representation of this string.
    `urlsafe=True` encodes string as urlsafe base64
    """
    if urlsafe:
        b64 = base64.urlsafe_b64encode(data.encode("ascii"))
        return b64.decode("ascii")
    b64 = base64.b64encode(data.encode("ascii"))
    return b64.decode("ascii")