wcwidth: Unicode String Width Measurement
wcwidth is a Python library that measures the displayed width of Unicode strings in a terminal, ensuring accurate text formatting. The current version is 0.6.0, released on January 22, 2022. The library is actively maintained with a release cadence of approximately every few months.
Warnings
- breaking Version 0.5.0 dropped support for many historical versions of wide and zero Unicode tables, now only the latest Unicode version (17.0.0) is supported. The 'unicode_version' keyword in wcwidth() functions is ignored, and list_versions() returns a tuple with only the latest Unicode version.
- deprecated The 'unicode_version' keyword in wcwidth() functions was deprecated in version 0.5.0 and is ignored in version 0.6.0.
- gotcha The wcwidth function may not handle all Unicode characters correctly, especially those with ambiguous widths. It's important to test with a variety of characters to ensure accurate results.
Install
-
pip install wcwidth
Imports
- wcwidth
from wcwidth import wcwidth
Quickstart
from wcwidth import wcwidth
# Measure the width of a Unicode string
text = 'Hello, 世界'
width = wcwidth(text)
print(f'The width of the text is: {width}')