Registry / tcolorpy

tcolorpy

JSON →
library0.1.7pypypi✓ verified 23d ago

tcolorpy is a Python library designed to apply true color (24-bit RGB) for terminal text, providing a rich set of methods to style strings with foreground, background, and various ANSI effects. The current version is 0.1.7, and the project maintains an active, though not rapid, release cadence with a focus on Python version compatibility and packaging improvements.

pip install tcolorpy
INSTALL
IMPORT
SIG · TCOLORPY
T
tcolorpy
pythonv0.1.7
Install
1.7s avg
Import
24ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.7 · 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.026s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.022s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

Color
from tcolorpy import Color
RgbColor
from tcolorpy import RgbColor
AnsiFgColor
from tcolorpy import AnsiFgColor
tcolorpy (as color)
import tcolorpy as color
Commonly imported as 'color' for direct access to predefined colors and functions.

Demonstrates basic usage of predefined colors, custom RGB, 256-color ANSI codes, and checking terminal true color capability.

import tcolorpy as color # Basic red text print(color.RED('Hello, tcolorpy!')) # Custom RGB color with bold style print(color.RgbColor(255, 100, 0, 'Orange Bold Text').bold()) # 256-color foreground and background print(color.AnsiFgColor(27, 'Deep Green FG') + color.AnsiBgColor(235, ' Dark Gray BG')) # Check if the terminal supports true colors if color.is_true_color_terminal(): print(color.BLUE('Your terminal supports true colors!')) else: print(color.YELLOW('True color support not detected.'))
Debug
Known issues
breakingSupport for Python 3.7 and 3.8 was dropped in version 0.1.7. Users on these Python versions must upgrade their Python interpreter or pin 'tcolorpy' to a version less than 0.1.7.
fix
Upgrade Python to 3.9+ or install 'tcolorpy<0.1.7'.
affects: >=0.1.7
breakingSupport for Python 3.6 was dropped in version 0.1.3. Users on Python 3.6 must install 'tcolorpy' to a version less than 0.1.3.
fix
Upgrade Python to 3.7+ (preferably 3.9+) or install 'tcolorpy<0.1.3'.
affects: >=0.1.3
gotchaThe `tcolorpy.disable()` and `tcolorpy.enable()` functions globally control whether colors are rendered. If you find colors are unexpectedly not appearing, verify that coloring hasn't been disabled.
fix
Ensure `tcolorpy.enable()` has been called if colors are not displaying as expected. These functions affect the global state.
affects: All
gotchaTerminal true color (24-bit RGB) support is not universal across all terminal emulators and operating systems. While `tcolorpy` includes `is_true_color_terminal()` for detection, colors may not render as intended if the user's terminal lacks full support.
fix
Consider checking `tcolorpy.is_true_color_terminal()` before applying true colors, or be aware that fallback to 256-color or basic ANSI colors may be necessary for broader compatibility.
affects: All
Errors
Common errors & fixes
ImportError: cannot import name 'color' from 'tcolorpy'
The main class for applying colors and styles in tcolorpy is named 'Color' (with a capital C), not 'color'.
fix
Use the correct capitalization when importing: `from tcolorpy import Color`
AttributeError: 'function' object has no attribute 'bold'
You are attempting to chain a styling method (like `bold()`) directly onto a color class method (e.g., `Color.red`) without first passing the text. `Color.red` is a function that returns a `Color` object when called with text.
fix
First call the color method with your text, and then chain the styling method onto the resulting `Color` object: `Color.red("my text").bold()`
AttributeError: 'Color' object has no attribute 'foreground'
The `tcolorpy.Color` object uses shorthand methods `fg()` and `bg()` for setting foreground and background colors, respectively, not `foreground()` or `background()`.
fix
Use `fg()` or `bg()` to set the colors. For example: `Color("my text").fg("red")`
Upgrade
Version history
0.1.7latest on PyPI · released Dec 29, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
6
Amazon
1
Resources
tcolorpy — pip install tcolorpy · libregistry