Registry / observability / colorful

colorful

JSON →
library0.5.8pypypi✓ verified 26d ago

Colorful is a Python library that provides expressive and consistent terminal string styling. It supports various color modes including 8 ANSI, 256 ANSI, and true colors, along with predefined styles (like Solarized) and custom color palettes. The current version is 0.5.8, and it is actively maintained with several releases per year.

pip install colorful
INSTALL
IMPORT
SIG · COLORFUL
C
colorful
observabilitypythonv0.5.8
Install
1.5s avg
Import
27ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.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.032s · 18.6MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.022s · 19MB
17MB installed
● package 17MB
Code
Verified usage

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

colorful
import colorful as cf
The official documentation and common practice recommend importing colorful with the alias `cf` for concise usage.

This quickstart demonstrates basic text coloring, combining styles, using f-strings for dynamic content, extending the color palette, and employing context managers for specific color modes. The recommended import is `import colorful as cf`.

import colorful as cf import os # Basic text styling print(cf.red('Hello, red World!')) print(cf.bold_green('This is bold and green.')) # Combining styles using bitwise operators print(cf.italic & cf.coral_on_beige | 'Styled with italic, coral text on beige background.') # Using f-strings (Python >= 3.6) user_name = os.environ.get('USER', 'Guest') print(f'{cf.blue_on_white}Hello, {user_name}! Enjoy Colorful!{cf.reset}') # Extending the default color palette cf.update_palette({'companyOrange': '#f4b942', 'companyBlue': '#4287f5'}) print(cf.companyOrange_on_companyBlue('Custom company colors!')) # Using a context manager for temporary color mode with cf.with_8_ansi_colors() as c: print(c.bold_magenta('This text uses 8 ANSI colors only.')) # Printing with format-string like syntax cf.print('{c.cyan}Formatted {c.underline}output{c.reset} with {c.yellow}placeholders{c.reset}', name=cf.bold_white('Colorful'))
Debug
Known issues
breakingPython 2 support was officially dropped in `colorful` version 0.5.5. Attempts to use versions 0.5.5 or newer with Python 2 will result in `ImportError` or other compatibility issues.
fix
Ensure your project runs on Python 3.5 or newer. Upgrade your Python environment if necessary.
affects: >=0.5.5
gotchaVersions prior to 0.5.7 might encounter an `AttributeError: 'DualOutput' object has no attribute 'isatty'` when interacting with specific terminal output streams, particularly in certain environments or configurations.
fix
Upgrade to `colorful` version 0.5.7 or later to resolve this `isatty` attribute issue.
affects: <0.5.7
gotchaIn versions older than 0.5.5, there were known issues with `setup(colormode=NO_COLORS)` not behaving as expected and the `__str__` representation of `ColorfulString` objects not always correctly returning a plain string.
fix
Upgrade to `colorful` version 0.5.5 or later to ensure correct `NO_COLORS` setup and reliable string representation.
affects: <0.5.5
gotchaOlder versions (prior to 0.5.4) had an incorrect implementation of the `__getattr__` protocol, which could lead to unexpected behavior when dynamically accessing color and style attributes (e.g., `cf.some_color_name`).
fix
Upgrade to `colorful` version 0.5.4 or later to ensure correct dynamic attribute access for colors and styles.
affects: <0.5.4
gotchaAlthough `colorful` generally manages color resets, explicitly using `cf.reset` or context managers (`with cf.with_...`) is good practice. Without proper resets, especially if a script terminates unexpectedly, terminal color settings might 'bleed' into subsequent shell output, affecting the console's appearance after your program exits.
fix
Always use `cf.reset` at the end of a block of colored output, or prefer context managers (e.g., `with cf.with_true_colors() as c:`) which automatically handle scope, to ensure color settings are restored.
affects: All versions
breaking`colorful.print()` does not support a `name` keyword argument. Passing 'name' or any other unsupported keyword arguments to `colorful.print()` will result in a `TypeError`.
fix
Review calls to `colorful.print()` and remove any unsupported keyword arguments, such as `name`.
affects: All versions
gotchaThe `Colorful.print()` method does not support keyword arguments for string formatting, leading to a `TypeError` when arguments like `name=value` are passed to it. This suggests that `Colorful.print()` expects positional arguments or a different formatting mechanism, and does not interpret keyword arguments as variables for placeholder substitution.
fix
Prepare your formatted string using Python's f-strings or `.format()` method *before* passing it to `Colorful.print()`. For example, instead of `cf.print('{c.cyan}Formatted output with {c.yellow}placeholders{c.reset}', name=cf.bold_white('Colorful'))`, use `cf.print(f'{c.cyan}Formatted output with {c.yellow}placeholders{c.reset}'.format(name=cf.bold_white('Colorful')))` or `cf.print(f'{c.cyan}Formatted output with {c.yellow}placeholders{c.reset} (name={cf.bold_white('Colorful')})')`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'colorful'
The 'colorful' library is not installed in the Python environment being used, or there is a typo in the import statement.
fix
Install the library using pip: `pip install colorful`
AttributeError: 'Colorful' object has no attribute 'nonExistentStyle'
The user is attempting to call a color or style method (e.g., `nonExistentStyle`) on the `colorful` object that does not exist or is misspelled.
fix
Refer to the `colorful` documentation for a list of available colors and styles (e.g., `cf.red`, `cf.bold_white`, `cf.magenta_on_cyan`).
AttributeError: module 'colorful' has no attribute 'red'
The user is trying to access color methods directly from the `colorful` module (e.g., `colorful.red`) instead of through the instantiated `Colorful` object, which is typically aliased as `cf`.
fix
Import `colorful` as `cf` and use the `cf` object to apply styles: `import colorful as cf` then `print(cf.red('Hello World'))`.
Upgrade
Version history
0.5.8latest on PyPI · released Oct 29, 2025
Audit
Dependencies
coloramaoptionalUsed internally for Windows compatibility to process ANSI escape sequences; not a hard dependency and automatically handled by `colorful` if `colorama` is present.
Agent activity
30 hits · last 30 days
node
24
OpenAI (training)
1
Resources
colorful — pip install colorful · libregistry