Skip to main content

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

  1. Clone the repo.
  2. Install dependencies (e.g., pip install -e .[dev]).
  3. Run tests:
    pytest
    

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

textprep_lite-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

textprep_lite-0.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

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

Hashes for textprep_lite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 08bce2337572f1b4435d628edf613afc4091574f0af8153f7aa57bc00bdc48ae
MD5 feee47baf9fca3f649ea1d298c142259
BLAKE2b-256 625ab1461c7b840781696f04dca3117dc286d5c0f36bbe3d751cae56f7bef2c3

See more details on using hashes here.

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

Hashes for textprep_lite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c48593a46f904aa3f359d141424b85a164036ace8fbec3a22278e9182f70c042
MD5 535b8e06667058ec8b661dc0902309cf
BLAKE2b-256 7fc93c6e3e6f5f500cceed7c8ac37a7c5d65a7a35036da56f5e34a6301f80c4e

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