wcwidth
Measures the displayed width of unicode strings in a terminal
This package has a good security score with no known vulnerabilities.
Community Reviews
Lightweight, zero-dependency utility that just works for terminal width calculations
From an operations perspective, this library is a dream. Memory footprint is negligible, performance is excellent for typical use cases (sub-microsecond for most strings), and there's literally nothing to configure or tune. No connection pools, no retries, no timeouts - it's just a pure function that does math. The Unicode table data is embedded, so no file I/O or network calls to worry about.
The main limitation is that it's synchronous-only and you can't lazy-load the Unicode tables, so every process pays the ~100KB memory cost upfront. For high-scale deployments with thousands of workers, this adds up, though it's still minor. Breaking changes between 0.1.x and 0.2.x around East Asian Width handling caught some users, but the API has been stable since.
Best for: Terminal UI libraries, CLI tools, and logging formatters that need accurate string width calculations for alignment and wrapping.
Avoid if: You need graphical display measurements or have extremely memory-constrained environments where every 100KB matters.
Solid, focused utility with minimal attack surface but Unicode data lag
The main security consideration is that it bundles Unicode width tables that can lag behind current standards. This isn't a vulnerability per se, but could lead to display width miscalculations with newer emoji or Unicode additions. Input validation is implicit—the library accepts any string and handles malformed input gracefully without crashes. No network calls, no file I/O, no crypto—just deterministic character width lookups.
In practice, it's dead simple: call wcwidth() for single characters or wcswidth() for strings. The API is intentionally minimal, which I appreciate from a security perspective. The library doesn't expose stack traces or internal state on bad input, just returns sensible defaults.
Best for: CLI tools, terminal UI libraries, and text rendering where precise character width calculation is needed with minimal dependencies.
Avoid if: You need cutting-edge Unicode support for the very latest emoji or require real-time Unicode standard updates.
Lightweight, dependency-free utility that does one thing reliably well
The error handling is straightforward: invalid input returns -1 or raises standard Python exceptions. No custom exceptions to catch, no retry logic needed. It's deterministic and side-effect free, making it trivial to test and reason about. The main gotcha is remembering that wcwidth() returns width for a single character while wcswidth() handles strings—the naming trips people up initially.
From an operations perspective, this is a "set it and forget it" dependency. No logs to configure, no timeouts to tune, no resource cleanup. Version updates have been non-breaking in my experience. The Unicode version it implements may lag slightly behind the latest spec, but this rarely matters in practice for terminal applications.
Best for: Terminal-based applications needing accurate text width calculations for formatting tables, progress bars, or aligned output.
Avoid if: You need cutting-edge Unicode support for the very latest emoji or require grapheme cluster handling beyond display width.
Sign in to write a review
Sign In