ysskrishna logoysskrishna

Strip BOM

Invisible UTF-8 marks should not break your parsers, CSV headers, or string checks.

Built with
PyPI Packages
Text & Data Conversion
File & Path Utilities
Python
uv
PyPI
GitHub Actions
Pytest
Details
FreeMIT licenseCreated February 10, 2026Updated November 12, 2026
Share this product

Your file looks fine. Your parser disagrees.

The export opens in the editor with a normal first line. Run it through JSON or CSV and the first key or character fails. Compare two strings that should match and they do not. A colleague swears the files are identical. Somewhere at the start hides a UTF-8 byte order mark you never typed.

Strip BOM is a small Python library that removes that prefix from strings, bytes, streams, and files.

Three invisible bytes should not own your Monday.

What you get

  • Clean text before parsers see it. Strip UTF-8 byte order mark from strings, bytes, streams, and files so structured data and string equality are not tripped by an invisible prefix.
  • Buffers handled with a safety check. The buffer helper validates UTF-8 before it strips; invalid sequences are left unchanged so you do not silently corrupt binary-ish payloads.
  • Large inputs without loading everything at once. Stream helpers process chunk by chunk so big files and streams stay memory efficient.
  • Files in text or binary mode. Read a path and get back content with the BOM removed when it was there.
  • Lightweight and free. No external dependencies; MIT licensed.

See what changes on one bad export

Picture an illustrative case: a partner drops a nightly CSV into shared storage. Your script reads the header row and every lookup on the first column fails because the column name carries an invisible prefix. The file helper reads the path, removes a leading UTF-8 byte order mark when present, and the header names line up with what your code expects. The same prefix that broke JSON from an API response or made two strings differ in tests is gone before your parser runs.

Ready to try it?

Frequently asked questions

Why not just open the file with utf-8-sig?

That helps when you only read from disk and you control the open call. When the payload is already a string or byte buffer from an API, a cache, or an upload, you need to strip the mark in place. This package offers helpers for strings, bytes, streams, and files.

How do I fix a CSV whose first column name will not match?

Some files from Windows editors and exports start with a UTF-8 byte order mark. The first header looks right in a viewer but does not match your code's key. Remove the mark from the file or string before the CSV reader runs.

Will stripping BOM break data that is not really UTF-8 text?

The buffer helper validates UTF-8 encoding before it strips. Invalid sequences are left unchanged rather than altered.

Can it handle a large file without reading the whole thing into memory?

Yes. Stream helpers yield chunks so you can process large files and streams without loading everything into memory at once.

What do I need to use it?

Python 3.8 or newer. Install from PyPI; the repository documents usage for strings, buffers, streams, and files.

Is it free?

Yes. It is open source under the MIT license. The package is listed as free, and you can install it from PyPI like any other open dependency.

Does it remove every kind of byte order mark?

No. It targets UTF-8 byte order mark handling, not every legacy encoding or non-UTF-8 BOM variant.

Continue exploring

ProductPyPIVideo Extensions

Video Extensions

A fast, honest first filter when a filename might be video.
File & Path Utilities
PyPI Packages
+5
ProductPyPIUnused Path

Unused Path

Stop overwriting downloads and exports. Get the next free filename, browser style.
File & Path Utilities
PyPI Packages
+5
ProductPyPIText Extensions

Text Extensions

Know which paths look like text before you open them. One shared list, no list upkeep.
File & Path Utilities
PyPI Packages
+5
ProductPyPIBinary Extensions

Binary Extensions

Know which paths look binary in Python, from a curated list of 250+ extensions with no extra dependencies.
File & Path Utilities
PyPI Packages
+5
ProductPyPIQuotes Convert

Quotes Convert

Flip single and double quotes in text without breaking nested escapes.
Text & Data Conversion
PyPI Packages
+5
ProductPyPISocial Links

Social Links

Users paste messy profile links. One Python library turns them into clean, comparable URLs.
PyPI Packages
Python
+4