🌈
Colorist for Python
🌈
Lightweight Python package that makes it easy and fast to print terminal messages in colors.
Prerequisites
- Python 3.9 or higher
- macOS
- It may work on Windows or Linux, but hasn't been tested
Installation
PyPI
pip3 install colorist
Homebrew
If you already have installed the Homebrew package manager for Mac and Linux, use this terminal command to tap Colorist for Python:
brew tap jakob-bagterp/colorist
And then install:
brew install colorist
Colors
Getting Started
Full Terminal Output
How to print a full line of colored text in the terminal:
from colorist import green, yellow, red
green("This is GREEN!")
yellow("This is YELLOW!")
red("This is RED!")
How it appears in the terminal:
Custom Terminal Output
How to customize terminal messages and change color inside a paragraph:
from colorist import Color
print(f"I want {Color.RED}red{Color.OFF} color inside this paragraph")
print(f"Both {Color.GREEN}green{Color.OFF} and {Color.YELLOW}yellow{Color.OFF} are nice colors")
How it appears in the terminal:
from colorist import BrightColor
print(f"I want {BrightColor.CYAN}cyan{BrightColor.OFF} color inside this paragraph")
How it appears in the terminal:
Remember to use Color.OFF
or BrightColor.OFF
every time you want to revert back to the default terminal text style. Otherwise the color may spill over and into other terminal messages.
Other String Formats
It's easier and more readable to use f-strings as in the examples above, but you can also use string format:
from colorist import Color
print("I want {0}red{1} color inside this paragraph".format(Color.RED, Color.OFF))
How it appears in the terminal:
Supported Text Colors
Effects
Getting Started
In addition to colors, Colorist for Python can also add effects to text messages in the terminal.
Full Terminal Output
How to print a full line of text effect in the terminal:
from colorist import effect_blink
effect_blink("This is BLINKING!")
How it appears in the terminal:
And this can also be combined with an optional color:
from colorist import Color, effect_blink
effect_blink("This is BLINKING!", Color.CYAN)
How it appears in the terminal:
Custom Terminal Output
How to customize terminal messages and change effect inside a paragraph:
from colorist import Effect
print(f"I want {Effect.UNDERLINE}underlined text{Effect.UNDERLINE_OFF} inside this paragraph")
print(f"I want {Effect.BOLD}emphasized text{Effect.BOLD_OFF} inside this paragraph")
How it appears in the terminal:
Effects can also be mixed with colors:
from colorist import Color, Effect
print(f"I want both {Color.RED}colored and {Effect.BLINK}blinking{Effect.BLINK_OFF} text{Color.OFF} inside this paragraph")
Similar to Color.OFF
and BrightColor.OFF
, remember to turn off an effect with the relevant reset option (e.g Effect.BOLD_OFF
, Effect.BOLD_OFF
, etc. or even just Effect.OFF
) every time you want to revert back to the default terminal text style. Otherwise the effect may spill over and into other terminal messages.
Supported Effects
Donate
This module is free to use. And if you like it, feel free to buy me a coffee.
Contribute
If you have suggestions or changes to the module, feel free to add to the code and create a pull request.
Report Bugs
Report bugs and issues here.