Clean invisible/control Unicode characters, normalize text, and optionally convert/remove emoji — with an explainable report.
Project description
unicode-sanity
Clean messy Unicode text: remove or escape invisible/bidi control characters, normalize to a consistent form, and optionally remove/alias emoji — with a clear, human-readable report of what changed.
Why?
Copy-pasted or scraped text often contains invisible junk (zero-width spaces, bidi control marks, BOMs) that break searching, matching, and CSV exports. unicode-sanity fixes these safely and explains what it did.
Install
pip install unicode-sanity
Usage
CLI
Run the sanitizer against a file or standard input:
unicode-sanity input.txt --out cleaned.txt --policy safe --escape-format brackets --explain --stats
--policy strictremoves invisible/bidi characters (default).--policy safereplaces them with visible tags such as[ZERO_WIDTH_SPACE].--policy auditleaves text unchanged and only reports findings.- Add
--emoji removeto strip emoji or--emoji aliasto turn them into:shortcodes:. --normalizecontrols Unicode normalization (NFC,NFKC,NFD,NFKD, ornone).
Python API
from unicode_sanity import sanitize
result = sanitize("Cafe\u0301 \u200B", policy="safe", emoji="alias", explain=True)
print(result.text)
# -> Café <ZERO_WIDTH_SPACE>
print(result.report)
# -> ['normalized to NFC', 'escaped 1 invisible/bidi character(s)', 'converted emoji to aliases']
The sanitize helper returns a CleanResult dataclass with the cleaned text, an optional report, and per-issue counts that are handy for dashboards or logs.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unicode_sanity-0.1.0.tar.gz.
File metadata
- Download URL: unicode_sanity-0.1.0.tar.gz
- Upload date:
- Size: 12.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ff4074ad5d41c796a960c8081780e9adb93ed8fb4d5638c0c05524cd889e85a
|
|
| MD5 |
6b32f4e53066a9620de0426b8b2afb02
|
|
| BLAKE2b-256 |
f843443b3f3920b2f485653d622055dc28ebb32d7ac83f56b6597b1a0465b50d
|
File details
Details for the file unicode_sanity-0.1.0-py3-none-any.whl.
File metadata
- Download URL: unicode_sanity-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e75b72b8969b8d3c76cb0387a49810a5648794042411f687d13a0699b693ab3e
|
|
| MD5 |
2cfdc8fc205d6ed50b3639d4a45ab24e
|
|
| BLAKE2b-256 |
2cf8174084e34db3580827fa5b9eb0298a7aeb8b8a13233a0e3fc3c8c0bc1aa3
|