cwcwidth
Python bindings for wc(s)width
What it is and what it does
cwcwidth is a C-based Python library that calculates how many columns a Unicode string will occupy when displayed in a terminal. It wraps POSIX wcwidth/wcswidth functions (or Markus Kuhn's implementation on non-POSIX systems) and provides the same API as the pure-Python wcwidth package, but with significantly faster execution through Cython compilation.
The library is useful when you need accurate terminal rendering calculations—for instance, when aligning text in CLI tools, formatting table output, or handling mixed-width characters (like CJK ideographs that occupy two columns). It has no runtime dependencies and supports modern Python versions (3.11+) across major platforms with prebuilt wheels.
Use it for:
- Calculate display width of strings containing East Asian characters for terminal table formatting.
- Align text output in CLI applications where mixed-width characters must be handled correctly.
- Truncate or pad Unicode strings to fit within a specific terminal column width.
- Build terminal UI libraries that need accurate character width calculations for layout.
- Validate or measure string display length in text processing pipelines.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
cwcwidth provides fast Python bindings for POSIX wcwidth and wcswidth functions to compute the printable display width of Unicode characters and strings on terminals.
Yes, if you need fast Unicode display-width calculations for terminal output. The library is actively maintained, has no security vulnerabilities, carries a permissive license, and offers substantial performance gains over pure-Python alternatives. Install friction is moderate but manageable with prebuilt wheels for all major platforms. Requires Python 3.11+.
Install
cwcwidth on PyPI
pip
pip install cwcwidthuv
uv add cwcwidthpoetry
poetry add cwcwidthInstalling cwcwidth
Before you install
Medium install friction due to compiled wheels, but well-supported across platforms (macOS arm64/x86_64, Linux x86_64/aarch64, Windows 32/64-bit, musl). Active maintenance with recent release.
License in practice
MIT license is permissive; you can use, modify, and distribute cwcwidth freely with minimal restrictions.
Quickstart
pip install cwcwidth
import cwcwidth
print(cwcwidth.wcwidth('a')) # 1
print(cwcwidth.wcswidth('コンニチハ, セカイ!')) # 19
Requires Python 3.11 or later.
Verify before relying
- Whether performance improvement over wcwidth remains significant in real-world terminal applications beyond the benchmark shown.
- Whether the limited Python API mode (via USE_LIMITED_API environment variable) affects performance or compatibility.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.11) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 286 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 575,923/month — #5,933 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cwcwidth-0.1.12-cp311-abi3-macosx_11_0_arm64.whl; cwcwidth-0.1.12-cp311-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; cwcwidth-0.1.12-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; cwcwidth-0.1.12-cp311-abi3-musllinux_1_2_aarch64.whl; cwcwidth-0.1.12-cp311-abi3-musllinux_1_2_x86_64.whl; cwcwidth-0.1.12-cp311-abi3-win32.whl; cwcwidth-0.1.12-cp311-abi3-win_amd64.whl; cwcwidth-0.1.12-cp311-cp311-macosx_11_0_arm64.whl; cwcwidth-0.1.12-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; cwcwidth-0.1.12-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; cwcwidth-0.1.12-cp311-cp311-musllinux_1_2_aarch64.whl; cwcwidth-0.1.12-cp311-cp311-musllinux_1_2_x86_64.whl; cwcwidth-0.1.12-cp311-cp311-win32.whl; cwcwidth-0.1.12-cp311-cp311-win_amd64.whl; cwcwidth-0.1.12-cp312-cp312-macosx_11_0_arm64.whl; cwcwidth-0.1.12-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; cwcwidth-0.1.12-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; cwcwidth-0.1.12-cp312-cp312-musllinux_1_2_aarch64.whl; cwcwidth-0.1.12-cp312-cp312-musllinux_1_2_x86_64.whl; cwcwidth-0.1.12-cp312-cp312-win32.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
wcwidthMeasures the displayed width of Unicode strings…
permissive · top 1,000 on PyPI
cchardetcchardet detects the character encoding of byte…
copyleft · top 5,000 on PyPI
rtfunicodeEncodes Unicode strings to RTF 1.5 command…
permissive · top 15,000 on PyPI
win_unicode_consoleFixes Unicode input and display in Python when…
permissive · top 15,000 on PyPI
anyasciiConverts Unicode text to ASCII-only equivalents…
permissive · top 5,000 on PyPI
graphemeuProvides string manipulation functions that…
permissive · top 5,000 on PyPI
texttableCreates formatted ASCII tables for console…
permissive · top 1,000 on PyPI
tangled-up-in-unicodeProvides detailed Unicode character properties…
permissive · top 15,000 on PyPI
fold-to-asciiConverts Unicode characters outside the basic…
permissive · top 15,000 on PyPI
unicode-segmentation-rsProvides Unicode text segmentation (graphemes,…
unclear · top 15,000 on PyPI