codext defines a far broader set of Base-encodings than in the original library.

Classical base 2^N encodings

This namely adds the classical BaseXX encodings like 16 (hexadecimal) and 32 (RFC 3548), which are not available in the native codecs.

Common base encodings with N a power of 2:

Codec Conversions Aliases Comment
base2 text <-> Base2 encoded text (base[-_]?2|bin)-inv(erted)?
base4 text <-> Base4 encoded text base[-_]?4-inv(erted) charset: 1234
base8 text <-> Base8 encoded text base[-_]?8-inv(erted) charset: abcdefgh
base16 text <-> Base16 encoded text base[-_]?16-inv(erted)
base32 text <-> Base32 encoded text base[-_]?32-inv(erted)
zbase32 text <-> ZBase32 encoded text z[-_]?base[-_]?32 human-oriented Base32
base64 text <-> Base64 encoded text base[-_]?64-inv(erted)


All the aliases are case insensitive for base encodings.

>>> codext.encode("test", "base2")
>>> codext.encode("test", "base2-inv")
>>> codecs.encode("this is a test", "base16")
>>> codecs.decode("7468697320697320612074657374", "base16")
'this is a test'
>>> codecs.encode("this is a test", "base16-inv")
>>> codext.encode("this is a test", "base32")
>>> codext.decode("ORUGS4ZANFZSAYJAORSXG5A=", "base32")
'this is a test'

Note that for base64, it overwrites the native base64_codec to also support en/decoding from str.

>>> codecs.encode("this is a test", "base64")
>>> codecs.decode("dGhpcyBpcyBhIHRlc3Q=", "base64")
'this is a test'

Generic base encodings

Codec Conversions Aliases Comment
base3 text <-> Base3 encoded text base[-_]?36(|[-_]inv(erted)?)
base36 text <-> Base36 encoded text base[-_]?36(|[-_]inv(erted)?)
base58 text <-> Base58 encoded text base[-_]?58(|[-_](bc|bitcoin|rp|ripple|fl|flickr|short[-]?url|url)) supports Bitcoin, Ripple and short URL
base62 text <-> Base62 encoded text base[-_]?62(|[-_]inv(erted)?)
>>> codext.encode("test", "base3")
>>> codecs.encode("test", "base36")
>>> codecs.decode("4WMHTK6UZL044O91NKCEB8", "base36")
'this is a test'
>>> codext.encode("this is a test", "base58")
>>> codext.encode("this is a test", "base58-ripple")
>>> codext.encode("this is a test", "base58-url")
>>> codecs.encode("test", "base62")
>>> codecs.encode("this is a test", "base62")

Generic encodings

Base encodings are available for any N other than the ones explicitely specified using the "-generic" suffix. Their charsets consist of printable characters from the string module for N up to 100 and for characters composed from the 256 possible ordinals for a greater N.

>>> codext.encode("test", "base3-generic")
>>> codext.encode("test", "base17-generic")


This encoding relies on the base64 library and is only supported in Python 3.

Codec Conversions Aliases Comment
ascii85 text <-> ascii85 none Python 3 only
>>> codext.encode("this is a test", "ascii85")
>>> codext.decode("FD,B0+DGm>@3BZ'F*%", "ascii85")
'this is a test'
>>> with open("ascii85.txt", 'w', encoding="ascii85") as f:
    f.write("this is a test")
>>> with open("ascii85.txt", encoding="ascii85") as f:
'this is a test'

Other base encodings

Codec Conversions Aliases Comment
base85 text <-> Base85 encoded text base[-_]?85 Python 3 only (relies on base64 module)
base100 text <-> Base100 encoded text base[-_]?100|emoji Python 3 only

With Python 3, base85 and base100 (emoji's) are also supported.

>>> codecs.encode("this is a test", "base85")
>>> codecs.decode("bZBXFAZc?TVIXv6b94", "base85")
'this is a test'
>>> codecs.encode("this is a test", "base100")
>>> codecs.decode("👫👟👠👪🐗👠👪🐗👘🐗👫👜👪👫", "base100")
'this is a test'