skillfed

cwcwidth

Python bindings for wc(s)width

cwcwidth v0.1.12 575.9K downloads/30d#5,933 on PyPI8
Permissive license MIT Active released

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 cwcwidth

uv

uv add cwcwidth

poetry

poetry add cwcwidth

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersProgramming Language :: Python :: 3Topic :: Software Development :: Libraries :: Python Modules

Tags

unicode character display widthterminal string width calculationwcwidth python bindingseast asian character widthterminal column widthunicode display lengthwcswidth implementation
unicode-handlingterminal-uiperformance-critical

More Python Modules packages