METADATA 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. Metadata-Version: 2.4
  2. Name: graphemeu
  3. Version: 0.7.2
  4. Summary: Unicode grapheme helpers
  5. Project-URL: Homepage, https://github.com/timendum/grapheme
  6. Project-URL: Documentation, https://graphemeu.readthedocs.io/
  7. Author-email: Alvin Lindstam <alvin.lindstam@gmail.com>
  8. Maintainer: Timendum
  9. License: Copyright (c) 2017 The Python Packaging Authority (PyPA)
  10. Copyright (c) 2014 Mapbox
  11. Copyright (c) 2017 Alvin Lindstam
  12. Copyright (c) 2025 Timendum
  13. Permission is hereby granted, free of charge, to any person obtaining a copy
  14. of this software and associated documentation files (the "Software"), to deal
  15. in the Software without restriction, including without limitation the rights
  16. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  17. copies of the Software, and to permit persons to whom the Software is
  18. furnished to do so, subject to the following conditions:
  19. The above copyright notice and this permission notice shall be included in all
  20. copies or substantial portions of the Software.
  21. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. SOFTWARE.
  28. License-File: LICENSE
  29. Keywords: grapheme,unicode
  30. Classifier: Development Status :: 4 - Beta
  31. Classifier: Intended Audience :: Developers
  32. Classifier: Programming Language :: Python
  33. Requires-Python: >=3.7
  34. Provides-Extra: dev
  35. Requires-Dist: pytest; extra == 'dev'
  36. Provides-Extra: docs
  37. Requires-Dist: sphinx; extra == 'docs'
  38. Requires-Dist: sphinx-autobuild; extra == 'docs'
  39. Description-Content-Type: text/x-rst
  40. grapheme
  41. ========
  42. A Python package for working with user perceived characters. More specifically,
  43. string manipulation and calculation functions for working with grapheme cluster
  44. groups (graphemes) as defined by the `Unicode Standard Annex #29 <http://unicode.org/reports/tr29/>`_.
  45. `documentation <https://graphemeu.readthedocs.io/>`_
  46. .. code-block:: console
  47. pip install graphemeu
  48. Or similar.
  49. The currently supported version of Unicode: 16.0.0.
  50. This package is a fork of `grapheme <https://github.com/alvinlindstam/grapheme>`_ by Alvin Lindstam.
  51. What? Why?
  52. ==========
  53. Unicode strings are made up of a series of unicode characters, but a unicode character does not
  54. always map to a user perceived character. Some human perceived characters are represented as two
  55. or more unicode characters.
  56. However, all built in python string functions and string methods work with single unicode characters
  57. without considering their connection to each other.
  58. .. code-block:: python
  59. >>> string = 'u̲n̲d̲e̲r̲l̲i̲n̲e̲d̲'
  60. >>> len(string)
  61. 20
  62. >>> grapheme.length(string)
  63. 10
  64. >>> string[:3]
  65. 'u̲n'
  66. >>> grapheme.slice(string, 0, 3)
  67. 'u̲n̲d̲'
  68. This library implements the unicode default rules for extended grapheme clusters, and provides
  69. a set of functions for string manipulation based on graphemes.
  70. Documentation
  71. =============
  72. See `<https://graphemeu.readthedocs.io/en/latest/>`_.
  73. When should I consider graphemes instead of unicode characters?
  74. ===============================================================
  75. You should consider working with graphemes over unicode code points when:
  76. * You wish to count characters as perceived by users.
  77. * You wish to split or truncate text at some user perceived lengths.
  78. * You wish to split or truncate text without risk of corrupting the characters.
  79. * Formatting text by length, such as creating text based tables in monospaced fonts
  80. You should work with normal python string functions when:
  81. * You wish to count or split by unicode codepoints for compliance with storage
  82. limitations (such as database maximum length)
  83. * When working with systems that put limits on strings by unicode character
  84. lengths
  85. * When you prioritize performance over correctness (see performance notes below)
  86. * When working with very long strings (see performance notes below)
  87. * If simplicity is more important than accuracy
  88. Performance
  89. ===========
  90. Calculating graphemes require traversing the string and checking each character
  91. against a set of rules and the previous character(s). Because of this, all
  92. functions in this module will scale linearly to the string length.
  93. Whenever possible, they will only traverse the string for as long as needed and return
  94. early as soon as the requested output is generated. For example, the `grapheme.slice`
  95. function only has to traverse the string until the last requested grapheme is found, and
  96. does not care about the rest of the string.
  97. You should probably only use this package for testing/manipulating fairly short strings
  98. or with the beginning of long strings.
  99. When testing with a string of 10 000 ascii characters, and a 3.1 GHz processor, the execution
  100. time for some possible calls is roughly:
  101. ================================================================ ==========================
  102. Code Approximate execution time
  103. ================================================================ ==========================
  104. `len(long_ascii_string)` 3.0e-10 seconds
  105. `grapheme.length(long_ascii_string)` 4.3e-05 seconds
  106. `grapheme.length(long_ascii_string, 500)` 2.6e-06 seconds
  107. `long_ascii_string[0:100]` 1.3e-09 seconds
  108. `grapheme.slice(long_ascii_string, 0, 100)` 6.3e-07 seconds
  109. `long_ascii_string[:100] in long_ascii_string` 7.8e-09 seconds
  110. `grapheme.contains(long_ascii_string, long_ascii_string[:100])` 9.9e-07 seconds
  111. `long_ascii_string[-100:] in long_ascii_string` 2.0e-08 seconds
  112. `grapheme.contains(long_ascii_string, long_ascii_string[-100:])` 6.9e-05 seconds
  113. ================================================================ ==========================
  114. Execution times may improve in later releases, but calculating graphemes is and will continue
  115. to be notably slower than just counting unicode code points.
  116. Examples of grapheme cluster groups
  117. ===================================
  118. This is not a complete list, but a some examples of when graphemes use multiple
  119. characters:
  120. * CR+LF
  121. * Hangul (korean)
  122. * Emoji with modifiers
  123. * Combining marks
  124. * Zero Width Join
  125. Development quick start
  126. =======================
  127. If you wish to contribute or edit this package, create a fork and clone it.
  128. Then install and run the tests.
  129. .. code-block:: console
  130. uv run --extra dev -m pytest
  131. For the documentation, use:
  132. .. code-block:: console
  133. uv run --extra docs sphinx-autobuild docs dist/www
  134. Unicode version upgrade
  135. -----------------------
  136. The library will issue a new release for each new unicode version.
  137. The steps necessary for this:
  138. 1. Verify that there has been no material changes to the rulesets in Unicode
  139. `Annex #29 <http://unicode.org/reports/tr29/>`_ (see modifications).
  140. 2. Download the `data files <http://www.unicode.org/Public/>`_ from unicode into the unicode-data folder.
  141. For the given version, some are in `ucd` and some are in `ucd/auxiliary`.
  142. 3. Run `make process-data-files` to parse those files (will update the
  143. `grapheme_break_property.json` and `derived_core_property.json` files).
  144. 4. Update the unicode version in the documentation and in the source code.
  145. 5. Bump the version.