Updated on July 21, 2026.
When working with data, you might encounter BOMs (Byte Order Marks).
Byte Order Marks are special Unicode character codes
(U+FEFF) placed at the beginning of a text files that
signal to a program how to interpret the source text. The Unicode can be
encoded in 8-bit, 16-bit, or 32-bit integers. Each mark has its BOM
representation by which it can be identified.
BOMs can lead to surprises when handling files:
BOM use is optional. Its presence interferes with the use of UTF-8 by software that does not expect non-ASCII bytes at the start of a file but that could otherwise handle the text stream.
When reading files in Python, you can use the utf-8-sig
encoding.
import csv
with open("filepath.csv", "r", encoding="utf-8-sig") as file:
reader = csv.reader(file)The byte sequence of the BOM differs per Unicode encoding (including UTF-8), and none of the sequences is likely to appear at the start of text streams stored in other encodings. Therefore, placing an encoded BOM at the start of a text stream can indicate that the text is Unicode and identify the encoding scheme used. This use of the BOM is called a “Unicode signature”.
Python also provides a handful of byte sequence constants in the
codecs library to represent BOMs.
import codecs
codecs.BOM
codecs.BOM_BE
codecs.BOM_LE
codecs.BOM_UTF8
codecs.BOM_UTF16
codecs.BOM_UTF16_BE
codecs.BOM_UTF16_LE
codecs.BOM_UTF32
codecs.BOM_UTF32_BE
codecs.BOM_UTF32_LE