Python base64 Module
Example
Encode and decode a string using Base64:
import base64
s = "Linus".encode()
b = base64.b64encode(s)
print(b)
print(base64.b64decode(b).decode())
Try it Yourself »
Definition and Usage
The base64 module encodes binary data into ASCII strings using Base16, Base32, Base64, and related encodings.
Use it to transfer binary data in text-based formats, handle URLs safely, or embed small assets in text documents.
Members
Member | Description |
---|---|
a85decode() | Decode ASCII85 (Base85) encoded data. |
a85encode() | Encode binary data using ASCII85. |
b16decode() | Decode Base16 (hex) encoded data. |
b16encode() | Encode binary data using Base16 (hex). |
b32decode() | Decode Base32 encoded data. |
b32encode() | Encode binary data using Base32. |
b32hexdecode() | Decode Base32 using the extended hexadecimal alphabet. |
b32hexencode() | Encode using Base32 with the extended hexadecimal alphabet. |
b64decode() | Decode Base64 encoded data. |
b64encode() | Encode binary data using Base64. |
b85decode() | Decode Base85 encoded data. |
b85encode() | Encode binary data using Base85. |
decodebytes() | Decode Base64 from a bytes-like object (line breaks allowed). |
encodebytes() | Encode to Base64 and return a bytes object with line breaks. |
standard_b64decode() | Decode Base64 using the standard alphabet. |
standard_b64encode() | Encode Base64 using the standard alphabet. |
urlsafe_b64decode() | Decode Base64 using the URL-safe alphabet. |
urlsafe_b64encode() | Encode Base64 using the URL-safe alphabet. |