Base64
The `base64` module encodes binary data as ASCII text and decodes it back. It is essential for email attachments, data URLs, API authentication, and storing binary data in text formats. The guide walks through Encoding & Decoding, Base64 Variants, Practical Applications. `base64.b64encode(b"data")` returns bytes. `base64.b64decode("ZGF0YQ==")` decodes. Both accept and return bytes — decode to string with `.decode("utf-8")` if needed. Standard Base64 uses A-Z, a-z, 0-9, +, /, and = for padding. URL-safe variant: `base64.urlsafe_b64encode()` uses - and _ instead of + and /. `base64.b64encode()` standard encoding with padding. `base64.urlsafe_b64encode()` URL-safe variant. `base64.b32encode()` Base32 (case-insensitive, useful for human-readable). `base64.b16encode()` Base16 = hex. `base64.a85encode()` Ascii85 (more efficient, used in Adobe PostScript). Choose standard Base64 for general use, URL-safe for URLs and filenames, Base32 for manual transcription. Data URIs: encode images inline in HTML/CSS — `data:image/png;base64,...`. Email attachments (MIME uses Base64). API authentication: Basic Auth header is `base64(user:pass)`. Store binary in JSON: encode as Base64 string. QR codes: encode payload as Base64 for binary data. JWT tokens use URL-safe Base64 for header, payload, and signature.