Registry / serialization / ansiwrap

ansiwrap

JSON →
library0.8.4pypypi✓ verified 22d ago

ansiwrap provides text wrapping capabilities similar to Python's standard `textwrap` module, but it is specifically designed to correctly handle strings that contain ANSI control sequences for colors and styles. It correctly calculates the effective length of a string by ignoring these non-printable control codes. The latest release is version 0.8.4, published in January 2019, indicating a maintenance-focused or slow release cadence.

pip install ansiwrap
INSTALL
IMPORT
SIG · ANSIWRAP
A
ansiwrap
serializationpythonv0.8.4
Install
1.6s avg
Import
17ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.4 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fill
from ansiwrap import fill
Primary function for wrapping text.
shorten
from ansiwrap import shorten
Primary function for truncating text.
ansilen
from ansiwrap import ansilen
Calculates the printable length of a string, ignoring ANSI codes.
strip_color
from ansiwrap import strip_color
Removes all ANSI escape codes from a string.

This example demonstrates how to use `ansiwrap` to fill and shorten a string containing ANSI color codes, calculate its effective display length, and strip the colors. It uses the `ansicolors` library to generate the colored text.

from ansiwrap import fill, shorten, ansilen, strip_color from colors import red, blue, green, color # Requires 'ansicolors' package s = ' '.join([ red('This string'), blue('is going on a bit long'), green('and may need to be'), color('shortened a bit', fg='purple') ]) print('-- Original string --') print(s) print(f'Original length (Python): {len(s)}') print(f'Printable length (ansiwrap): {ansilen(s)}') print('\n-- Now filled to 20 columns --') print(fill(s, 20)) print('\n-- Now shortened / truncated to 20 columns --') print(shorten(s, 20, placeholder='...')) print('\n-- Strip colors --') print(strip_color(s)) print(f'Stripped length: {len(strip_color(s))}')
Debug
Known issues
breakingansiwrap version 0.8.4 is not directly compatible with Python 3.12 due to the removal of the `imp` module, leading to `ModuleNotFoundError` during import.
fix
As of April 2026, there is an unmerged pull request on GitHub to address Python 3.12 compatibility. Users may need to apply a patch manually or await an official release. Consider using alternative libraries if Python 3.12+ compatibility is critical.
affects: 0.8.4 on Python 3.12+
gotchaThe library has not had a new release since January 2019. This suggests it is in maintenance mode or no longer actively developed, which might lead to limited support for newer Python features, potential unaddressed bugs, or future compatibility issues.
fix
Be aware of the project's maintenance status. For critical applications, thorough testing against your Python environment is recommended, and consider contributing fixes or exploring more actively maintained alternatives if long-term support is a concern.
affects: All versions
gotchaThe example code often relies on an external library like `ansicolors` (or `colors`) to generate ANSI-colored strings. This dependency is not automatically installed with `ansiwrap` and must be installed separately for the quickstart examples to run as shown.
fix
Ensure `ansicolors` (or your preferred ANSI styling library) is installed if you intend to use `ansiwrap` with colored text, e.g., `pip install ansicolors`.
affects: All versions
Upgrade
Version history
0.8.4latest on PyPI · released Jan 23, 2019
Audit
Dependencies
ansicolorsoptionalUsed in examples to generate ANSI colored strings that ansiwrap can process. Not a strict runtime dependency for ansiwrap itself, but essential for using its core feature with colored text.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
ansiwrap — pip install ansiwrap · libregistry