unicategories is a Python library that provides a Unicode category database, generated and cached on setup. It exposes a dictionary of `RangeGroup` instances, containing all Unicode category character ranges detected on your system. This module offers an efficient way to work with Unicode character classifications, such as 'Letter, uppercase' (Lu) or 'Number, decimal digit' (Nd), by storing ranges rather than individual characters for memory efficiency. The current version is 0.1.2, released on April 2, 2023.
pip install unicategoriesVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import the `categories` dictionary, access `RangeGroup` instances by category code (e.g., 'Lu' for uppercase letters), retrieve characters or code points using `characters()` and `codes()` iterators, and check for character inclusion with `has()`.
Use `list(categories['Lu'].characters())` if a full list is required, but be mindful of memory usage for very large categories.
Ensure your project is running on Python 3.5 or newer. Python 3 handles Unicode natively, reducing potential encoding issues.
Combine `unicategories` for category-based filtering/lookup with `unicodedata` for individual character properties. Example: `import unicodedata; char_name = unicodedata.name('A')`.Always specify the correct encoding, preferably UTF-8, when opening files or decoding byte strings. For file operations: `with open('filename.txt', 'r', encoding='utf-8') as f: ...`. For byte strings: `my_bytes.decode('utf-8')`.Use raw strings by prefixing with `r` (e.g., `r'C:\Users\...'`) or double the backslashes (`'C:\\Users\\...'`). Alternatively, use `pathlib.Path` for platform-agnostic path handling: `from pathlib import Path; path = Path('C:/Users/...')`.Explicitly encode the Unicode string into a suitable byte encoding, such as UTF-8, using the `.encode()` method: `my_unicode_string.encode('utf-8')`.No dependency data recorded yet.