--- id: ansiwrap version: "0.8.4" license: Apache License 2.0 license_treatment: permissive maintenance: active --- # ansiwrap — textwrap, but savvy to ANSI colors and styles License: permissive · Maintenance: active · Downloads: 1.2M/mo ## What it is and what it does ansiwrap extends Python's standard textwrap module to handle ANSI escape sequences correctly. When you wrap or fill text containing ANSI color codes, textwrap miscalculates line length because it counts the raw bytes of invisible control codes. ansiwrap strips those codes during measurement, so wrapped lines respect actual display width, not byte length. The package provides wrap(), fill(), and shorten() functions mirroring textwrap's API, plus utility functions like ansilen() to measure visible text length and strip_color() to remove codes entirely. It has no runtime dependencies and works across Python 2 and 3, making it straightforward to drop into terminal UI code or CLI tools that use colored output. Use it for: - Format colored log output to fit terminal width without breaking lines due to invisible codes - Wrap help text in CLI tools that use ANSI colors for emphasis without miscounting line length - Truncate colored status messages to a fixed display width in terminal dashboards - Process multi-line colored text and reflow it to new widths while preserving styling - Strip ANSI codes from colored strings when you need plain text for logging or storage ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Wraps and formats text while correctly handling ANSI color and style codes, treating them as invisible to line length calculations the way textwrap cannot. Yes. The package solves a real problem (textwrap + ANSI codes) with no dependencies, permissive licensing, and active maintenance. It's small, focused, and widely downloaded. Install it if you're building terminal UIs or CLI tools with colored output that need proper text wrapping. ## Install pip install ansiwrap uv add ansiwrap poetry add ansiwrap ## Installing ansiwrap Before you install: Low friction: pure Python wheel with no runtime dependencies. Maintenance is active with recent commits, though the latest release was in 2019. License in practice: Apache License 2.0 is permissive; you can use this in commercial and proprietary projects with minimal restriction. Quickstart: pip install ansiwrap from ansiwrap import wrap, fill, shorten, ansilen, strip_color lines = wrap('colored text', width=20) filled = fill('colored text', width=20) shortened = shorten('colored text', 20, placeholder='...') Verify before relying: - Whether the package handles all ANSI escape sequences or only color/style codes - Performance characteristics on very long strings or high-volume wrapping operations - Exact Python version support beyond the classifiers listed (2.6, 2.7, 3.3-3.7) ## Package facts - License: Apache License 2.0 (permissive) - Python support: unspecified - Install friction: low - Maintenance: active - Downloads: 1.2M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags ANSI color text wrapping, textwrap with color codes, wrap colored terminal text, ANSI aware text formatting, terminal text wrapping, colored text line breaking, terminal-ui, ansi-colors [View on SkillFed](https://skillfed.io/packages/ansiwrap) · [View on PyPI](https://pypi.org/project/ansiwrap/)