Does python have an equivalent to Javascript's 'btoa'

I'm trying to find an exact equivalent to javascript's function 'btoa', as I want to encode a password as base64. It appears that there are many options however, as listed here:

Is there an exact equivalent to 'btoa' in python?


  • Python's Base64:

    import base64
    encoded = base64.b64encode(b'Hello World!')
    # value of encoded is SGVsbG8gV29ybGQh

    Javascript's btoa:

    var str = "Hello World!";
    var enc = window.btoa(str);
    var res = enc;
    // value of res is SGVsbG8gV29ybGQh

    As you can see they both produce the same result.