Skip to main content

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 strict removes invisible/bidi characters (default).
  • --policy safe replaces them with visible tags such as [ZERO_WIDTH_SPACE].
  • --policy audit leaves text unchanged and only reports findings.
  • Add --emoji remove to strip emoji or --emoji alias to turn them into :shortcodes:.
  • --normalize controls Unicode normalization (NFC, NFKC, NFD, NFKD, or none).

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

unicode_sanity-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unicode_sanity-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

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

Hashes for unicode_sanity-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1ff4074ad5d41c796a960c8081780e9adb93ed8fb4d5638c0c05524cd889e85a
MD5 6b32f4e53066a9620de0426b8b2afb02
BLAKE2b-256 f843443b3f3920b2f485653d622055dc28ebb32d7ac83f56b6597b1a0465b50d

See more details on using hashes here.

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

Hashes for unicode_sanity-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e75b72b8969b8d3c76cb0387a49810a5648794042411f687d13a0699b693ab3e
MD5 2cfdc8fc205d6ed50b3639d4a45ab24e
BLAKE2b-256 2cf8174084e34db3580827fa5b9eb0298a7aeb8b8a13233a0e3fc3c8c0bc1aa3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page