7.8.4. Python Specific Encodings
A number of predefined codecs are specific to Python, so their codec names have no meaning outside Python. These are listed in the tables below based on the expected input and output types (note that while text encodings are the most common use case for codecs, the underlying codec infrastructure supports arbitrary data transforms rather than just text encodings). For asymmetric codecs, the stated purpose describes the encoding direction.
The following codecs provide unicode-to-str encoding [1] and str-to-unicode decoding [2], similar to the Unicode text encodings.
CodecAliasesPurpose
idna
mbcs
dbcs
Windows only: Encode operand according to the ANSI codepage (CP_ACP)
palmos
Encoding of PalmOS 3.5
punycode
Implements
raw_unicode_escape
Produce a string that is suitable as raw Unicode literal in Python source code
rot_13
rot13
Returns the Caesar-cypher encryption of the operand
undefined
Raise an exception for all conversions. Can be used as the system encoding if no automatic coercion between byte and Unicode strings is desired.
unicode_escape
Produce a string that is suitable as Unicode literal in Python source code
unicode_internal
Return the internal representation of the operand
New in version 2.3: The idna and punycode encodings.
The following codecs provide str-to-str encoding and decoding [2].
CodecAliasesPurposeEncoder/decoder
base64_codec
base64, base-64
Convert operand to multiline MIME base64 (the result always includes a trailing '\n')
bz2_codec
bz2
Compress the operand using bz2
hex_codec
hex
Convert operand to hexadecimal representation, with two digits per byte
quopri_codec
quopri, quoted-printable, quotedprintable
Convert operand to MIME quoted printable
string_escape
Produce a string that is suitable as string literal in Python source code
uu_codec
uu
Convert the operand using uuencode
zlib_codec
zip, zlib
Compress the operand using gzip
str objects are also accepted as input in place of unicode objects. They are implicitly converted to unicode by decoding them using the default encoding. If this conversion fails, it may lead to encoding operations raising UnicodeDecodeError.
[2]
(1, 2) unicode objects are also accepted as input in place of str objects. They are implicitly converted to str by encoding them using the default encoding. If this conversion fails, it may lead to decoding operations raising UnicodeEncodeError.