all Python 3base64function
base64.urlsafe_b64decode()
Base64
Decodes Base64 in the URL-safe alphabet ('-' and '_'). The counterpart of urlsafe_b64encode.
Syntax
base64.urlsafe_b64decode(s)
Up to Python 3.14 inclusive, a string without '=' padding (as in a JWT) raises binascii.Error; in 3.15 the padded parameter defaults to False and such a string passes. The portable way is to add the '=' yourself: s + '=' * (-len(s) % 4). In 3.15, accepting '+' and '/' here is deprecated and emits FutureWarning.
Examples
import base64
s = 'aGk'
print(base64.urlsafe_b64decode(s + '=' * (-len(s) % 4))) # → b'hi'
print(base64.urlsafe_b64decode(b'-_8=')) # → b'\xfb\xff'
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy