____
/ __ \ ______ ____ / /____ _____
/ / / // ____// __ \ / // __ \/ ___/
/ /_/ // /____/ /_/ // // /_/ / /
/_____/ \____/ \____//_/ \____/_/
pip install dcolor-drawiksfrom dcolor import color
print(color("hello!", "#ff0000"))
print(color("hello!", (255, 0, 0)))
print(color("hello!", "red"))
print(color("hello!", "#ff0000", "bold", "underline"))- 🎨 hex colors —
"#ff0000"or"#f00" - 🌈 rgb colors —
(255, 0, 0) - 🔢 256-color palette —
196(0-255) - 🏷️ named colors —
"red","cyan","orange"... - 🎭 background colors —
bg="#ff0000" - ✨ styles —
bold,italic,underline,strike,dim,blink - 📱 auto terminal detection — no colors in piped output
- 🪟 Windows — native Windows 10+ support (no dependencies)
- 🚫 no dependencies — stdlib only
from dcolor import color
print(color("error", "#ff0000"))
print(color("success", "#00ff00"))
print(color("info", "#3b82f6"))short hex also works:
print(color("text", "#f00")) # same as #ff0000print(color("text", (255, 165, 0)))print(color("text", 196)) # orange
print(color("text", fg=196, bg=21)) # orange on bluecolors 0-255 supported (see 256 terminal colors)
print(color("text", "red"))
print(color("text", "cyan"))
print(color("text", "orange"))available names: black, red, green, yellow, blue, magenta, cyan, white, grey, orange, pink, purple, brown, lime, teal
print(color("text", "red", "bold"))
print(color("text", "#ff0000", "bold", "underline"))
print(color("text", "cyan", "italic", "strike"))available styles: bold, dim, italic, underline, blink, strike
print(color("text", fg="#ffffff", bg="#ff0000")) # white on red
print(color("text", bg="#00ff00")) # background onlyprint(color("text", None, "bold"))
print(color("text", None, "underline", "italic"))from dcolor import strip
raw = color("hello", "#ff0000", "bold")
clean = strip(raw) # "hello"by default dcolor doesn't color output if it's piped or redirected:
python script.py > log.txt # no colors
python script.py | cat # no colors
python script.py # colors (in terminal)force colors on:
print(color("text", "#ff0000", force=True)) # always coloredon Windows 10+ (Build 10586+) works natively. on older Windows versions, escape codes render as garbage.
from dcolor import color
print(color("[ERROR]", "#ff4444", "bold"), "something went wrong")
print(color("[SUCCESS]", "#44ff44", "bold"), "everything is fine")
print(color("[WARN]", "#ffaa00", "bold"), "watch out")
print(color("[INFO]", "#888888"), "just fyi")from dlogger import logger
from dcolor import color
logger.info(color("payment received", "#44ff44", "bold"))
logger.error(color("connection failed", "#ff4444"))