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()
client.strip(" hi ")
client.collapse_whitespace("a b\t c")
client.slugify("Héllo, World!")
client.to_snake_case("camelCaseString")
client.strip_accents("café résumé")
client.remove_html_tags("<p>Hi <b>x</b>")
client.clean(" messy\t\ttext\r\nhere ")
cleanup() is a singleton: calling it again anywhere returns the
same instance.
assert cleanup() is cleanup()
Available helpers
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.