New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

cleanup-string

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Malware was recently detected in this package.

Affected versions:

1.0.0

cleanup-string

String-cleanup utilities.

pipPyPI
Version
1.0.0
Maintainers
1
Created

cleanup-string

String-cleanup utilities exposed through a single client class.

  • Everything is used through the cleanup() singleton — create it, then call its methods.
  • Pure standard library — zero third-party dependencies.
  • Type-hinted (py.typed). Installable with pip on Python 3.9 – 3.13.

Installation

python -m pip install cleanup-string

Usage

from cleanup_string import cleanup

client = cleanup()          # singleton — always the same instance

client.strip("  hi  ")                     # 'hi'
client.collapse_whitespace("a   b\t c")    # 'a b c'
client.slugify("Héllo, World!")            # 'hello-world'
client.to_snake_case("camelCaseString")    # 'camel_case_string'
client.strip_accents("café résumé")        # 'cafe resume'
client.remove_html_tags("<p>Hi <b>x</b>")  # 'Hi x'
client.clean("  messy\t\ttext\r\nhere ")   # 'messy text here'

cleanup() is a singleton: calling it again anywhere returns the same instance.

assert cleanup() is cleanup()   # True

Available helpers

MethodWhat it does
strip(s)Trim leading/trailing whitespace
collapse_whitespace(s)Collapse whitespace runs to a single space + trim
remove_whitespace(s)Remove all whitespace
normalize_newlines(s)\r\n / \r → \n
remove_control_chars(s)Drop control chars (keeps tab/newline/CR)
remove_html_tags(s)Strip <...> tags
remove_urls(s)Remove http(s):// / www. URLs
remove_punctuation(s)Remove Unicode punctuation
remove_digits(s)Remove digits
remove_non_ascii(s)Drop non-ASCII characters
normalize_unicode(s, form="NFC")Unicode normalisation
strip_accents(s)Remove diacritics (café → cafe)
to_snake_case(s)snake_case
to_kebab_case(s)kebab-case
to_camel_case(s)camelCase
slugify(s)Lowercase hyphenated URL slug
truncate(s, length, suffix="…")Truncate with a suffix
clean(s)Normalise + de-control + collapse whitespace

License

MIT — see LICENSE.

FAQs

Related posts