pyuca is a pure-Python implementation of the Unicode Collation Algorithm (UCA), designed to sort non-English strings correctly by accounting for linguistic rules such as accents, contractions, and expansions. It implements multi-level comparison and passes UCA conformance tests for various Unicode versions, depending on the Python environment's `unicodedata` library. The library's current version is 1.2, released in September 2017. While functional and still used (e.g., in Fedora packages), it is not actively maintained and may be considered slightly obsolete by some.
pip install pyucaVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize a `Collator` and use its `sort_key` method with Python's built-in `sorted()` function to achieve linguistically correct sorting of Unicode strings. The `Collator` automatically adapts to the Unicode version supported by your Python installation.
Evaluate if the existing functionality meets your needs. For projects requiring active development, newer Unicode standard support, or continuous maintenance, investigate other internationalization libraries (e.g., those based on ICU, if available for Python) as alternatives.
For high-performance scenarios, benchmark `pyuca` against your requirements. Consider initializing the `Collator` once and reusing the instance rather than creating new ones repeatedly. If performance remains an issue, explore alternative libraries or optimize data processing workflows.
For intricate language-specific collation needs beyond the Default Unicode Collation Element Table (DUCET) provided by `pyuca`, you might need to use other tools or libraries. Python's built-in `locale` module can provide locale-specific sorting but is known to have thread-safety issues, especially in web server environments.
Ensure your Python environment is sufficiently up-to-date to access the desired Unicode standard version. `pyuca` v1.2 supports Unicode 8.0.0 on Python 3.5, 9.0.0 on 3.6, and 10.0.0 on Python 3.7 and later.
Use `pyuca.Collator` to generate culturally and linguistically correct sort keys: ```python from pyuca import Collator collator = Collator() words = ["résumé", "resume", "résiste"] sorted_words = sorted(words, key=collator.sort_key) # sorted_words will be: ['resume', 'résumé', 'résiste'] ```
Initialize the `Collator` object only once and reuse it across multiple sorting operations. If performance remains critical, consider profiling your code and exploring alternative collation libraries that might offer C-backed implementations or better optimization for your specific use case, if available.
Verify if the expected sorting behavior is a standard UCA rule or a highly localized tailoring. While `pyuca` is not designed for easy custom rule injection, for very specific needs, other internationalization libraries (e.g., `PyICU` for Pythong with ICU, though not a direct `pyuca` alternative) might offer more control over collation rules and tailoring options.
No dependency data recorded yet.