bases

raw JSON →
0.3.0 verified Fri May 01 auth: no python

Python library for general Base-N encodings (e.g., base64, base32, base16, hex, binary, and custom alphabets). Version 0.3.0 supports Python 3.7+ and uses runtime type validation. Release cadence is low; no releases since 2022.

pip install bases
error ImportError: cannot import name 'Base64Encoding' from 'bases'
cause Older version (pre-0.1.0) may not exist or incorrect import path.
fix
Upgrade to latest version: pip install --upgrade bases
error AttributeError: 'Base64Encoding' object has no attribute 'encode'
cause The method is named `export`, not `encode`.
fix
Use encoding.export(data) for encoding.
error ValueError: Alphabet must not contain duplicate characters
cause Custom alphabet contains repeated characters.
fix
Remove duplicate characters from the alphabet string.
gotcha The `import_bytes` method returns bytes, not string. Do not assume it returns a string.
fix Use `encoding.import_bytes(encoded)` and handle bytes output.
deprecated Python 3.6 support was removed in v0.2.0. If your project requires Python 3.6, pin to v0.1.1.
fix Upgrade to Python 3.7+ or use `bases==0.1.1`.
gotcha Custom alphabets must be strings of unique characters without duplicates. Violation raises ValueError.
fix Ensure alphabet has no duplicate characters.

Import Base64Encoding, encode bytes, and decode back.

from bases import Base64Encoding
encoding = Base64Encoding()
data = b'hello world'
encoded = encoding.export(data)
print(encoded)  # Output: aGVsbG8gd29ybGQ=
decoded = encoding.import_bytes(encoded)
print(decoded)  # Output: b'hello world'