strip-ansi

raw JSON →
0.1.1 verified Mon Apr 27 auth: no python

A minimal library to strip ANSI escape sequences from strings. Designed to remove terminal color codes and control sequences. Version 0.1.1, stable, no recent updates. Requires Python >=3.6.

pip install strip-ansi
error AttributeError: module 'strip_ansi' has no attribute 'strip_ansi'
cause Using 'import strip_ansi' instead of 'from strip_ansi import strip_ansi'.
fix
Change to 'from strip_ansi import strip_ansi'.
error ImportError: cannot import name 'strip_ansi' from 'strip_ansi'
cause Pip installed the package incorrectly or a different package named 'strip_ansi' exists.
fix
Uninstall and reinstall with 'pip install --force-reinstall strip-ansi'.
gotcha The library does not handle all edge cases of ANSI sequences (e.g., non-standard or malformed sequences).
fix If you need comprehensive handling, consider using 're' or other libraries like 'colorama'.
gotcha The function is named the same as the package, which can cause naming conflicts if you import the package directly.
fix Always use 'from strip_ansi import strip_ansi' or alias the import.

Import and use the function to strip ANSI codes.

from strip_ansi import strip_ansi
text = "\x1b[31mHello\x1b[0m World"
clean = strip_ansi(text)
print(clean)  # Output: Hello World