all Python 3codecsterm
codecs.CodecInfo
codec registry
A codec registry record: the name plus the codec's functions and classes — encode, decode, stream and incremental ones. codecs.lookup returns it, and a custom search function builds it.
Syntax
codecs.CodecInfo(encode, decode, streamreader=None, streamwriter=None, incrementalencoder=None, incrementaldecoder=None, name=None)
It is a four-item tuple subclass (encode, decode, streamreader, streamwriter), a relic of the old API, so unpacking into four names works while incrementaldecoder and name exist only as attributes. encode and decode are stateless and return a pair (result, length consumed), not the bare result. You build one only to register your own codec; pass name=, or the name attribute stays None.
Examples
import codecs
info = codecs.lookup('utf-8')
print(info.name, isinstance(info, tuple)) # → utf-8 True
print(info.encode('я')) # → (b'\xd1\x8f', 1)
print(info.decode(b'ab')) # → ('ab', 2)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy