base64
UtilitiesEncoding & decoding
What is base64?
The base64 module is part of the Python standard library and provides functions for encoding binary data to ASCII text (and decoding it back). Base64 encoding is used everywhere in computing — embedding images in HTML, encoding attachments in email, transmitting binary data in JSON APIs, and generating auth tokens.
Since base64 is a built-in Python module, it works instantly in PyRun without any imports or micropip downloads. It's a great module to explore for understanding data encoding, token structures, and binary-to-text conversion patterns.
Code Example
Encode, decode, and inspect binary data as text.
Base64 Encoding
Try in Editorimport base64
import json
original = "Hello from PyRun!"
encoded = base64.b64encode(original.encode()).decode()
print("Original :", original)
print("Base64 :", encoded)
decoded = base64.b64decode(encoded).decode()
print("Decoded :", decoded)
url_safe = base64.urlsafe_b64encode(b"data for a URL: /path?q=1&v=2").decode()
print("\nURL-safe:", url_safe)
payload = {"user": "alice", "role": "admin", "exp": 9999999999}
token = base64.b64encode(json.dumps(payload).encode()).decode()
print("\nJWT-style token:", token)
print("Decoded payload:", json.loads(base64.b64decode(token)))Why run base64 in PyRun?
- ✦ Zero setup — no pip install, no virtual environment, no Python download
- ✦ Instant results — powered by WebAssembly, runs locally in your browser
- ✦ Share your code — generate a link and anyone can run it instantly
- ✦ Works offline — after first load, PyRun runs without internet