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.
import 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
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.