Lightweight text cleaning and anonymization for real-world NLP
Project description
textprep-lite
Lightweight text cleaning and anonymization for real-world NLP.
textprep-lite is a tiny Python library that standardizes text normalization and anonymization in 1–2 function calls, designed for ML/NLP workflows.
Installation
pip install textprep-lite
Quickstart
from textprep_lite import clean_text, anonymize_text, preprocess_text
raw = "Hey!! <br> This is John \nContact: john.doe@example.com, +44 7700 900123"
# Basic cleaning
cleaned = clean_text(raw)
print(cleaned)
# Output: "hey!! this is john contact: john.doe@example.com, +44 7700 900123"
# Anonymization
anon = anonymize_text(raw)
print(anon)
# Output: "Hey!! <br> This is John \nContact: [REDACTED], [REDACTED]"
# Full pipeline
processed = preprocess_text(raw)
print(processed)
# Output: "hey!! this is john contact: [redacted], [redacted]"
Configuration
clean_text
| Argument | Default | Description |
|---|---|---|
lowercase |
True |
Convert text to lowercase. |
strip_html |
True |
Remove HTML tags. |
normalize_whitespace |
True |
Collapse multiple spaces/newlines. |
strip_accents |
False |
Normalize Unicode accents to ASCII. |
remove_punct |
False |
Remove punctuation. |
remove_digits |
False |
Remove digits. |
keep_newlines |
False |
Preserve newlines during whitespace normalization. |
anonymize_text
| Argument | Default | Description |
|---|---|---|
mask_emails |
True |
Mask email addresses. |
mask_phones |
True |
Mask phone numbers. |
mask_urls |
True |
Mask URLs. |
mask_ip |
False |
Mask IPv4 addresses. |
replacement |
"[REDACTED]" |
Replacement string for masked items. |
Why textprep-lite?
Real-world text is messy. You repeatedly need to normalize whitespace, strip HTML, and mask PII. Instead of copying the same regex snippets into every notebook, textprep-lite offers a tested, reusable, and composable way to clean your text data.
Testing & Quality
textprep-lite is designed for reliability.
- Unit Tests: Comprehensive coverage for all cleaning and anonymization logic.
- Stress Tested: Verified against edge cases (empty strings, emojis, mixed IP/phone formats) and synthetic logs.
- Clean API: Type-hinted and documented.
Contributing
- Clone the repo.
- Install dependencies (e.g.,
pip install -e .[dev]). - Run tests:
pytest
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 textprep_lite-0.1.0.tar.gz.
File metadata
- Download URL: textprep_lite-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
08bce2337572f1b4435d628edf613afc4091574f0af8153f7aa57bc00bdc48ae
|
|
| MD5 |
feee47baf9fca3f649ea1d298c142259
|
|
| BLAKE2b-256 |
625ab1461c7b840781696f04dca3117dc286d5c0f36bbe3d751cae56f7bef2c3
|
File details
Details for the file textprep_lite-0.1.0-py3-none-any.whl.
File metadata
- Download URL: textprep_lite-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c48593a46f904aa3f359d141424b85a164036ace8fbec3a22278e9182f70c042
|
|
| MD5 |
535b8e06667058ec8b661dc0902309cf
|
|
| BLAKE2b-256 |
7fc93c6e3e6f5f500cceed7c8ac37a7c5d65a7a35036da56f5e34a6301f80c4e
|