The `grapheme` library (current version 0.10.0) provides helpers for Unicode grapheme-aware string handling in Python. It enables accurate counting, slicing, and manipulation of strings based on user-perceived characters (graphemes) rather than Unicode code points. The library is actively maintained, supporting recent Unicode standards, and typically releases new versions a few times a year.
pip install graphemeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates how to use `grapheme.length()` and `grapheme.slice()` to correctly handle user-perceived characters (graphemes) compared to Python's default string operations, which work on Unicode code points.
Upgrade to Python 3.7 or newer, or pin `grapheme<0.7.0`.
Upgrade to Python 3.10 or newer, or pin `grapheme<0.9.0`.
Evaluate performance needs; for extremely long strings where approximate length or codepoint-based operations are acceptable, native string methods might be faster.
Use positive indices for `start` and `end` arguments when using `grapheme.slice()`.
Always use `grapheme.contains(main_string, sub_string)` for grapheme-aware substring checks.
Install the package using pip: `pip install grapheme`.
Use non-negative integer values for `start` and `end` when calling `grapheme.slice()`.
Use `grapheme.length()` to count graphemes, `grapheme.contains()` for grapheme-aware substring checks, or `list(grapheme.graphemes(your_string))` for iteration.
Ensure the argument passed as the string to `grapheme` functions is a valid string type.