clean-text
Functions to preprocess and normalize text.
What it is and what it does
clean-text is a text preprocessing library that normalizes messy user-generated content from the web and social media. It fixes unicode encoding errors, removes or replaces unwanted patterns (URLs, emails, phone numbers, IP addresses, code snippets), handles transliteration to ASCII, and supports language-specific rules for English and German. The package wraps ftfy for unicode repair and optionally uses unidecode for transliteration, falling back to Python's built-in unicodedata when unidecode is unavailable.
The library offers both a simple functional API (clean() for single strings, clean_texts() for batch processing with optional multiprocessing) and a scikit-learn compatible transformer for integration into ML pipelines. You can preserve specific text patterns using regex-based exceptions to prevent them from being modified during cleaning, and customize replacement tokens for different content types.
Use it for:
- Normalize scraped web or social media text before feeding it into NLP models or search indexing.
- Batch-clean large text datasets in parallel using n_jobs to speed up preprocessing on multi-core systems.
- Standardize user input in web applications by removing malformed unicode, URLs, and email addresses while preserving legitimate content.
- Prepare text for machine learning pipelines via the scikit-learn CleanTransformer for reproducible preprocessing steps.
- Transliterate accented or non-ASCII characters to ASCII equivalents for systems that require ASCII-only text.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Preprocesses and normalizes user-generated text by fixing unicode errors, removing or replacing URLs, emails, code snippets, and other patterns, with optional transliteration to ASCII and support for parallel batch processing.
Yes, if you need to clean messy user-generated text before NLP or indexing. The package is stable, permissively licensed, and has low install friction. The aging maintenance status (198 days since last release) is a minor concern but not a blocker for a mature text-cleaning utility. Consider it a solid choice for preprocessing pipelines, especially if you already use scikit-learn.
Install
clean-text on PyPI
pip
pip install clean-textuv
uv add clean-textpoetry
poetry add clean-textInstalling clean-text
Before you install
Low friction install with two lightweight runtime dependencies (emoji and ftfy). Last release was 198 days ago; maintenance status is aging but the package remains functional for its core use case.
License in practice
Licensed under Apache-2.0 (permissive), allowing commercial and private use with minimal restrictions. No GPL obligation unless you explicitly install the optional unidecode extra.
Quickstart
pip install clean-text
from cleantext import clean
result = clean("Yóù àré right!", fix_unicode=True, to_ascii=True, lower=True)
Requires Python 3.9 or later. Optional unidecode dependency (installed via clean-text[gpl]) provides better transliteration but carries GPL licensing; without it, falls back to Python's built-in unicodedata with slightly different output.
Verify before relying
- Whether the aging maintenance status (198 days since last release) affects bug fixes or feature requests going forward.
- Real-world performance of parallel processing (n_jobs parameter) on typical workloads.
- Consistency and quality differences between transliteration with and without unidecode in production use.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — emoji, ftfy |
| Maintenance | aging — 198 days since the last release |
| First released | |
| Downloads | 317,577/month — #7,659 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: clean_text-0.7.1-py3-none-any.whl
Keywords: natural-language-processing, text-cleaning, text-preprocessing, text-normalization, user-generated-content
Tags
More Linguistic packages
Detects and normalizes text encoding from…
permissive · top 100 on PyPI
tiktokentiktoken is a fast BPE tokenizer that converts…
permissive · top 1,000 on PyPI
chardetDetects character encoding and language in byte…
permissive · top 1,000 on PyPI
text-unidecodeConverts Unicode text to ASCII by…
copyleft · top 1,000 on PyPI
larkLark is a parsing library that builds abstract…
permissive · top 1,000 on PyPI
tree-sitterPython bindings to the tree-sitter parsing…
permissive · top 1,000 on PyPI
python-slugifyConverts text strings—including unicode, HTML…
permissive · top 1,000 on PyPI
UnidecodeConverts Unicode text to ASCII-safe…
copyleft · top 1,000 on PyPI
procesProces provides text preprocessing functions…
permissive · top 15,000 on PyPI
unicode-slugifyConverts strings into URL-friendly slugs while…
permissive · top 15,000 on PyPI
anyasciiConverts Unicode text to ASCII-only equivalents…
permissive · top 5,000 on PyPI
normalityNormality removes diacritics, punctuation, and…
permissive · top 15,000 on PyPI
bnunicodenormalizerNormalizes Bangla Unicode text by fixing…
permissive · top 15,000 on PyPI
fold-to-asciiConverts Unicode characters outside the basic…
permissive · top 15,000 on PyPI
rigourRigour provides data cleaning and validation…
permissive · top 15,000 on PyPI