Endec
raw JSON → 0.5.4 verified Fri May 01 auth: no python
A web-compatible encoding and decoding library for Python, leveraging a Rust backend via PyO3 for performance. Current version 0.5.4 supports Python >=3.8. Releases are frequent, with minor patches and version bumps. It provides encoding/decoding for base64, base32, base16, hex, and other formats.
pip install endec Common errors
error TypeError: a bytes-like object is required, not 'str' ↓
cause Passing a string to encode() instead of bytes.
fix
Call encode(b'your_string') or encode('your_string'.encode('utf-8')).
error ModuleNotFoundError: No module named 'endec.codecs' ↓
cause Trying to import from a submodule that is not exposed.
fix
Use from endec import Base64 instead of from endec.codecs import Base64.
error ValueError: Unsupported codec: 'base64' (string) ↓
cause Passing a string like 'base64' instead of the codec object.
fix
Use from endec import Base64; encode(data, Base64).
Warnings
breaking In v0.4.0, dropped support for PyPy 3.9 and 3.10. If you use PyPy, ensure you are on PyPy 3.11+. ↓
fix Upgrade to PyPy 3.11+ or pin endec to <0.4.0.
gotcha The encode function expects bytes input. Passing a string will raise a TypeError. ↓
fix Ensure input is bytes: encode(b'text') not encode('text').
gotcha The decode function returns bytes, not a string. Many users expect a string for base64. ↓
fix Use .decode() on the result to get a string: decode(encoded, Base64).decode('utf-8').
Imports
- Base64 wrong
from endec.codecs import Base64correctfrom endec import Base64 - encode wrong
from endec.coder import encodecorrectfrom endec import encode - decode wrong
import endec; endec.decode(...)correctfrom endec import decode
Quickstart
from endec import encode, decode, Base64
# Encode bytes to base64 string
data = b"hello world"
encoded = encode(data, Base64)
print(encoded) # aGVsbG8gd29ybGQ=
# Decode back
decoded = decode(encoded, Base64)
print(decoded) # b'hello world'