Install & Compatibility
Where this runs
tested against v0.2.0 · 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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
getchar
✓ from ansi2txt import getchar
✗ from ansi2txt import ansi2txt
putchar
✓ from ansi2txt import putchar
main
✓ from ansi2txt import main
This quickstart demonstrates how to import the `ansi2txt` function and use it to convert an ANSI-formatted byte string (or encoded unicode string) into plain text, stripping all control characters.
from ansi2txt import ansi2txt
# Example ANSI colored string (bytes)
ansi_text_bytes = b'\x1b[31mHello, \x1b[32mWorld!\x1b[0m This is \x1b[4mcolored\x1b[0m text.'
# Convert to plain text
plain_text = ansi2txt(ansi_text_bytes)
print(f"Original ANSI: {ansi_text_bytes.decode('utf-8')}")
print(f"Plain text: {plain_text}")
# Example with unicode string (needs encoding first)
ansi_text_str = '\u001b[33mWarning:\u001b[0m Something happened.'
plain_text_from_str = ansi2txt(ansi_text_str.encode('utf-8'))
print(f"Plain text from string: {plain_text_from_str}")
Debug
Known issues
gotchaThe `ansi2txt` function primarily expects byte strings (`bytes`) as input, reflecting its common use case with terminal output. While it can handle ASCII strings, passing a unicode string (`str`) directly will raise a TypeError if it contains non-ASCII characters or if it's not explicitly encoded.fixEnsure your input is a `bytes` object. If you have a unicode string, encode it first: `ansi2txt(your_string.encode('utf-8'))`. affects: All versions (0.1.0+)
gotchaThe library is designed for common ANSI SGR (Select Graphic Rendition) codes (colors, bold, underline). It may not fully support more complex or non-standard ANSI sequences, such as cursor positioning, screen clearing, or device control sequences, and might leave them in the output or strip them unexpectedly.fixFor specific edge cases with complex ANSI sequences, review the source code or consider pre-processing your input to handle specific sequences if they are critical and not stripped correctly.
affects: All versions (0.1.0+)
Upgrade
Version history
0.2.0latest on PyPI · released Feb 23, 2023
Audit
Dependencies
No dependency data recorded yet.