Registry / devops / ansicolors

ansicolors

JSON →
library1.1.8pypypi✓ verified 24d ago

The `ansicolors` library provides a simple way to add ANSI escape codes for foreground, background, and text styles to strings for terminal output. It supports 8-color, 256-color (xterm), and 24-bit RGB color definitions. The current version is 1.1.8, released in June 2017, and the project appears to be in maintenance mode due to lack of recent updates.

pip install ansicolors
INSTALL
IMPORT
SIG · ANSICOLORS
A
ansicolors
devopspythonv1.1.8
Install
1.6s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1.8 · 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.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

color
from colors import color
import ansicolors
The PyPI package name is 'ansicolors', but the main module to import is 'colors'.

Demonstrates basic 8-color, 256-color, and 24-bit RGB usage with foreground, background, and style options. Includes a check for terminal color support.

from colors import color import os # Basic 8-color print(color('Hello, ANSI!', fg='green')) print(color('Warning!', fg='black', bg='yellow', style='bold')) # Check for color support (common practice) if os.environ.get('NO_COLOR') is None and os.stdout.isatty(): # 256-color (xterm) example print("\n256-color palette (if supported):") for i in range(256): if i % 16 == 0: print() print(color(f'{i:03d}', fg=i), end=' ') print('\n') # 24-bit RGB example print(color('True Color!', fg=(255, 100, 50), style='underline')) print(color('Deep Blue Background', bg='#00008b', fg='white')) else: print("\nTerminal does not support ANSI colors or NO_COLOR is set.")
Debug
Known issues
gotchaThe PyPI package is named `ansicolors`, but the Python module to import is `colors`. Importing `ansicolors` directly will not work as expected.
fix
Always use `from colors import color` (or other symbols) after `pip install ansicolors`.
affects: 1.0.0 - 1.1.8
deprecatedThe library has not seen a release since June 2017. It is likely no longer actively maintained, meaning no new features, bug fixes, or compatibility updates for newer Python versions or terminal standards.
fix
Be aware that issues related to modern Python versions or advanced terminal features may not be addressed. Consider alternatives like `Rich` or `Colorama` for actively maintained solutions.
affects: 1.1.8 and older
gotchaNot all ANSI styles (e.g., `blink`, `concealed`) are universally supported across different terminal emulators. Relying on these for critical visual cues can lead to inconsistent user experiences.
fix
Use common styles like `bold`, `underline`, `italic` first, and test output on target terminals. Avoid less common or 'hardly ever supported' styles for essential information.
affects: All versions
gotchaAdvanced color modes (256-color and 24-bit RGB) are not supported by all terminal emulators. Output may not render correctly or fall back to basic 8-color approximations on incompatible terminals.
fix
Implement graceful degradation for terminals without full color support (e.g., using `os.stdout.isatty()` or checking `NO_COLOR` environment variable). Inform users about terminal requirements if advanced colors are crucial.
affects: All versions
gotchaOn older Windows consoles (prior to Windows 10's native ANSI support), ANSI escape codes may not render correctly without specific registry modifications (setting `VirtualTerminalLevel` to 1) or using modern terminals like Windows Terminal.
fix
For cross-platform compatibility, especially on Windows, consider using libraries like `Colorama` which automatically initialize ANSI support for older terminals, or inform users about needing a modern terminal or Windows 10+.
affects: All versions (on Windows)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'colors'
The 'ansicolors' package is not installed, which provides the 'colors' module.
fix
pip install ansicolors
ImportError: cannot import name 'red' from 'colors'
The 'ansicolors' package is not installed, leading to an import error when trying to access 'red' from 'colors'.
fix
pip install ansicolors
ImportError: No module named 'color'
The 'color' module is not installed or not found in the Python environment.
fix
pip install color
AttributeError: module 'colors' has no attribute 'red'
The user has imported the `colors` module (from `ansicolors`) but is trying to call `colors.red()` or access `colors.red`, expecting direct color functions or attributes that the `ansicolors` library does not expose.
fix
Call the `color()` function on the imported `colors` module, specifying the color via parameters: `import colors; print(colors.color('My text', fg='red'))`
ValueError: Unknown style: 'invalid_style_name'
The `style` parameter provided to the `color()` function contains an invalid or unsupported style name.
fix
Use one of the supported style names: `none`, `bold`, `faint`, `italic`, `underline`, `blink`, `blink2`, `negative`, `concealed`, `crossed`.
Upgrade
Version history
1.1.8latest on PyPI · released Jun 2, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources