Skip to main content

Python bindings for wc(s)width

Project description

Python bindings for wc(s)width

cwcwidth provides Python bindings for wcwidth and wcswidth functions defined in POSIX.1-2001 and POSIX.1-2008 based on Cython. These functions compute the printable length of a unicode character/string on a terminal. The module provides the same functions as wcwidth and its behavior is compatible.

On systems not conforming to POSIX.1-2001 and POSIX.1-2008, Markus Kuhn's implementation is used to provide the functionality.


  • Cython >= 0.28 (optional, only for building). If Cython is not available, the C files are not regenerated from their source.

Quick installation guide

cwcwidth can be installed via pip:

pip install cwcwidth

or by running:

python3 install


>>> import cwcwidth
>>> cwcwidth.wcwidth("a")
>>> cwcwidth.wcswidth("コ")
>>> cwcwidth.wcswidth("コンニチハ, セカイ!")
>>> cwcwidth.wcswidth("コンニチハ, セカイ!", 5)

Comparison with wcwidth

>>> import wcwidth, cwcwidth, timeit
>>> timeit.timeit(lambda: wcwidth.wcswidth("コンニチハ, セカイ!"))
>>> timeit.timeit(lambda: cwcwidth.wcswidth("コンニチハ, セカイ!"))


The code is licensed under the MIT license.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cwcwidth-0.1.8.tar.gz (38.2 kB view hashes)

Uploaded source

Built Distributions

cwcwidth-0.1.8-cp311-cp311-win_amd64.whl (18.4 kB view hashes)

Uploaded cp311

cwcwidth-0.1.8-cp311-cp311-win32.whl (17.0 kB view hashes)

Uploaded cp311

cwcwidth-0.1.8-cp310-cp310-win_amd64.whl (18.2 kB view hashes)

Uploaded cp310

cwcwidth-0.1.8-cp310-cp310-win32.whl (16.8 kB view hashes)

Uploaded cp310

cwcwidth-0.1.8-cp39-cp39-win_amd64.whl (18.2 kB view hashes)

Uploaded cp39

cwcwidth-0.1.8-cp39-cp39-win32.whl (16.8 kB view hashes)

Uploaded cp39

cwcwidth-0.1.8-cp38-cp38-win_amd64.whl (18.3 kB view hashes)

Uploaded cp38

cwcwidth-0.1.8-cp38-cp38-win32.whl (16.8 kB view hashes)

Uploaded cp38

cwcwidth-0.1.8-cp37-cp37m-win_amd64.whl (18.4 kB view hashes)

Uploaded cp37

cwcwidth-0.1.8-cp37-cp37m-win32.whl (16.8 kB view hashes)

Uploaded cp37

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page