Python String Utilities
python-string-utils is a small utility library (version 1.0.0, last updated March 2020) that provides functions for string validation and manipulation. It aims to be simple, 'pythonic', fast (using compiled regex), and free from external dependencies, with 100% code coverage. Its release cadence has been infrequent, with the last major update in March 2020.
Warnings
- gotcha The library has not been updated since March 2020 (version 1.0.0) and was last tested against Python versions 3.5-3.8. While it may still function on newer Python versions, active development and official compatibility for Python 3.9+ are not guaranteed, which could lead to unforeseen issues or a lack of support for modern Python features.
- gotcha Many string manipulation and validation tasks can now be handled efficiently and often more 'pythonically' using built-in Python features such as f-strings for formatting, the `re` module for complex regex patterns, and `pathlib` for robust path operations. Relying heavily on older utility libraries for these tasks might introduce unnecessary dependencies or overlook more idiomatic Python solutions.
- gotcha The `is_string` function specifically checks if an object is of type `str` and returns `False` for byte strings (`bytes`). This might be a footgun if you expect it to validate any string-like object, including byte strings, which are common in I/O or network operations.
Install
-
pip install python-string-utils
Imports
- is_email
from string_utils import is_email
- prettify
from string_utils import prettify
Quickstart
from string_utils import is_email, prettify, is_full_string
# Example 1: Validate an email address
email = "test@example.com"
print(f"'{email}' is a valid email: {is_email(email)}")
# Example 2: Prettify a string
unprettified_string = " unprettified string ,, like this one,will be\"prettified\" . it' s awesome! "
prettified_string = prettify(unprettified_string)
print(f"Original: '{unprettified_string}'")
print(f"Prettified: '{prettified_string}'")
# Example 3: Check for non-empty string
empty_string = ""
non_empty_string = "hello"
print(f"'{empty_string}' is a full string: {is_full_string(empty_string)}")
print(f"'{non_empty_string}' is a full string: {is_full_string(non_empty_string)}")