Unicode Width Approximation
A library for calculating the display width of Unicode strings in terminal/monospace environments.
Installation
pip install unicode-width-approximation
Usage
from unicode_width_approximation import get_string_width, get_codepoint_width
# Get width of strings
print(get_string_width("hello")) # 5
print(get_string_width("中文")) # 4
print(get_string_width("👨👩👧👦")) # 2
# Get width of single code points
print(get_codepoint_width(ord('A'))) # 1
print(get_codepoint_width(0x4E00)) # 2 (CJK)
print(get_codepoint_width(0x1F600)) # 2 (emoji)
API
get_string_width(s: str) -> int
Calculate the total display width of a UTF-8 encoded string.
get_codepoint_width(code: int) -> int
Get the display width of a single Unicode code point (0, 1, or 2).
is_wide_char(code: int) -> bool
Check if a code point is a wide character (East Asian Wide or Fullwidth).
is_zero_width(code: int) -> bool
Check if a code point is a zero-width character.
Width Rules
| Character Type | Width |
|---|---|
| Control characters (Cc) | 0 |
| Format characters (Cf) | 0 |
| Combining marks (Mn, Me) | 0 |
| East Asian Wide (W) | 2 |
| East Asian Fullwidth (F) | 2 |
| Emoji_Presentation | 2 |
| Other characters | 1 |
License
MIT License
Metadata
Release files for unicode-width-approximation 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| unicode_width_approximation-1.0.0.tar.gz | 7.1 kB | Without provenance | Details for unicode_width_approximation-1.0.0.tar.gz |
Release files / unicode_width_approximation-1.0.0.tar.gz
| Download URL | unicode_width_approximation-1.0.0.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9dfb7a8e922a14a8b631ab0efc99d1206f5d1b211122d5b593e56a9afe0a5030
|
|
BLAKE2b-256 checksum How to use checksums |
bbfbd4373b8da9d409c7f8aa0c88a76267405c4d3bfd90814dde81088ce3f2c1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.8.20
|
Security for unicode-width-approximation 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.