Encoding Modules

encodings.utf_8_sig

UTF-8 codec variant that emits a leading UTF-8 signature when encoding and consumes an optional leading signature when decoding. Useful for formats that expect a BOM; ordinary UTF-8 does not automatically strip that marker. Use the public utf-8-sig codec name.

Formal Syntax & Structure

python syntaxpython
import encodings.utf_8_sig

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import encodings.utf_8_sigencoded = "Tea".encode("utf-8-sig")print(encoded.hex())print(encoded.decode("utf-8-sig"))
Python Reference