unicode-sanity


Nameunicode-sanity JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryClean invisible/control Unicode characters, normalize text, and optionally convert/remove emoji — with an explainable report.
upload_time2025-10-22 16:46:12
maintainerNone
docs_urlNone
authorEklavya Tomar
requires_python>=3.9
licenseMIT License Copyright (c) 2025 Eklavya Tomar Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords bidi emoji normalization text-cleaning unicode zero-width
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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
```bash
pip install unicode-sanity
```

## Usage

### CLI
Run the sanitizer against a file or standard input:

```bash
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

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "unicode-sanity",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "bidi, emoji, normalization, text-cleaning, unicode, zero-width",
    "author": "Eklavya Tomar",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/f8/43/443b3f3920b2f485653d622055dc28ebb32d7ac83f56b6597b1a0465b50d/unicode_sanity-0.1.0.tar.gz",
    "platform": null,
    "description": "# unicode-sanity\n\n**Clean messy Unicode text**: remove or escape invisible/bidi control characters, normalize to a consistent form, and optionally remove/alias emoji \u2014 with a clear, human-readable report of what changed.\n\n## Why?\nCopy-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.\n\n## Install\n```bash\npip install unicode-sanity\n```\n\n## Usage\n\n### CLI\nRun the sanitizer against a file or standard input:\n\n```bash\nunicode-sanity input.txt --out cleaned.txt --policy safe --escape-format brackets --explain --stats\n```\n\n- `--policy strict` removes invisible/bidi characters (default).\n- `--policy safe` replaces them with visible tags such as `[ZERO_WIDTH_SPACE]`.\n- `--policy audit` leaves text unchanged and only reports findings.\n- Add `--emoji remove` to strip emoji or `--emoji alias` to turn them into `:shortcodes:`.\n- `--normalize` controls Unicode normalization (`NFC`, `NFKC`, `NFD`, `NFKD`, or `none`).\n\n### Python API\n\n```python\nfrom unicode_sanity import sanitize\n\nresult = sanitize(\"Cafe\\u0301 \\u200B\", policy=\"safe\", emoji=\"alias\", explain=True)\nprint(result.text)\n# -> Caf\u00e9 <ZERO_WIDTH_SPACE>\nprint(result.report)\n# -> ['normalized to NFC', 'escaped 1 invisible/bidi character(s)', 'converted emoji to aliases']\n```\n\nThe `sanitize` helper returns a `CleanResult` dataclass with the cleaned text, an optional report, and per-issue counts that are handy for dashboards or logs.\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Eklavya Tomar\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in\n        all copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n        THE SOFTWARE.",
    "summary": "Clean invisible/control Unicode characters, normalize text, and optionally convert/remove emoji \u2014 with an explainable report.",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/EklavyaT/unicode-sanity",
        "Repository": "https://github.com/EklavyaT/unicode-sanity"
    },
    "split_keywords": [
        "bidi",
        " emoji",
        " normalization",
        " text-cleaning",
        " unicode",
        " zero-width"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "2cf8174084e34db3580827fa5b9eb0298a7aeb8b8a13233a0e3fc3c8c0bc1aa3",
                "md5": "2cfdc8fc205d6ed50b3639d4a45ab24e",
                "sha256": "e75b72b8969b8d3c76cb0387a49810a5648794042411f687d13a0699b693ab3e"
            },
            "downloads": -1,
            "filename": "unicode_sanity-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2cfdc8fc205d6ed50b3639d4a45ab24e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7868,
            "upload_time": "2025-10-22T16:46:11",
            "upload_time_iso_8601": "2025-10-22T16:46:11.154680Z",
            "url": "https://files.pythonhosted.org/packages/2c/f8/174084e34db3580827fa5b9eb0298a7aeb8b8a13233a0e3fc3c8c0bc1aa3/unicode_sanity-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f843443b3f3920b2f485653d622055dc28ebb32d7ac83f56b6597b1a0465b50d",
                "md5": "6b32f4e53066a9620de0426b8b2afb02",
                "sha256": "1ff4074ad5d41c796a960c8081780e9adb93ed8fb4d5638c0c05524cd889e85a"
            },
            "downloads": -1,
            "filename": "unicode_sanity-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "6b32f4e53066a9620de0426b8b2afb02",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 12601,
            "upload_time": "2025-10-22T16:46:12",
            "upload_time_iso_8601": "2025-10-22T16:46:12.540916Z",
            "url": "https://files.pythonhosted.org/packages/f8/43/443b3f3920b2f485653d622055dc28ebb32d7ac83f56b6597b1a0465b50d/unicode_sanity-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-10-22 16:46:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "EklavyaT",
    "github_project": "unicode-sanity",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "unicode-sanity"
}
        
Elapsed time: 1.97825s