Skip to main content

import re def compress_whitespace(text: str) -> str: """ Collapse runs of spaces/tabs to a single space on each line, trim traili…

Project description

PyPI version License: MIT Downloads LinkedIn

whitespace_normalizer

whitespace_normalizer is a Python package designed to clean and standardize whitespace within text. It collapses multiple spaces and tabs into single spaces on each line, trims trailing whitespace, and removes entirely blank lines.

Installation

To install whitespace_normalizer, use pip:

pip install whitespace_normalizer

Usage

Using whitespace_normalizer is straightforward. Import the normalize_whitespace function and pass your string to it.

from whitespace_normalizer import normalize_whitespace

text_with_messy_whitespace = """
This is a   string   with
extra     spaces.

And some
trailing whitespace.   
"""

cleaned_text = normalize_whitespace(text_with_messy_whitespace)
print(cleaned_text)

This will output:

This is a string with
extra spaces.
And some
trailing whitespace.

Features

  • Collapses consecutive spaces and tabs into a single space per line.
  • Removes trailing whitespace from each line.
  • Eliminates empty lines from the text.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

whitespace_normalizer is licensed under the MIT License.

Author

Eugene Evstafev

  • LinkedIn: LinkedIn

Repository

https://github.com/chigwell/whitespace_normalizer

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

whitespace_normalizer-2025.9.14911.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

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

whitespace_normalizer-2025.9.14911-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file whitespace_normalizer-2025.9.14911.tar.gz.

File metadata

File hashes

Hashes for whitespace_normalizer-2025.9.14911.tar.gz
Algorithm Hash digest
SHA256 6c315a498372ed4b02788f9ce4ee5da62bc326b54f37be9364bc0995354278bf
MD5 a0866fae513794404447b474563eef61
BLAKE2b-256 ed7af0ec88c28ebbce0cc1013d1bf805b3e53f4b80cc42ce621749fb49912b6a

See more details on using hashes here.

File details

Details for the file whitespace_normalizer-2025.9.14911-py3-none-any.whl.

File metadata

File hashes

Hashes for whitespace_normalizer-2025.9.14911-py3-none-any.whl
Algorithm Hash digest
SHA256 fe279fb6436200885ba3cb1601dadd88ea2a0009964f7dfa932b44f09ec3a9f7
MD5 627a2f7b7b4b26c50df492bbefd9984a
BLAKE2b-256 3b92e5928389ff0fb109ecf6b7a24cd1864fcfe7caeac9e30d914ae2cfb972a0

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