[](https://github.com/jakob-bagterp/colorist-for-python/releases/latest)

[](https://github.com/jakob-bagterp/colorist-for-python/blob/master/LICENSE.md)
[](https://codecov.io/gh/jakob-bagterp/colorist-for-python)
[](https://github.com/jakob-bagterp/colorist-for-python/actions/workflows/test.yml)
# 🌈 Colorist for Python 🌈
Lightweight Python package that makes it easy and fast to print colored text in the terminal.
Ready to try? [Learn how to install](https://github.com/jakob-bagterp/colorist-for-python/blob/master/INSTALLATION.md).
## Getting Started
### Print Line of Colored Text
How to print a full line of colored text in the terminal:
```python
from colorist import green, yellow, red
green("This is GREEN!")
yellow("This is YELLOW!")
red("This is RED!")
```
How it appears in the terminal:

### Print Mixed Text Colors
How to customize colors inside a paragraph and print it in the terminal:
```python
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:

## Other Styling Options
### Print Bright Colors
Most terminals support bright colors that stand more out:
```python
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.
### Print Background Colors
```python
from colorist import bg_green, bg_yellow, bg_red
bg_green("This is GREEN background!")
bg_yellow("This is YELLOW background!")
bg_red("This is RED background!")
```
How it appears in the terminal:

Background colors can also be mixed inside a paragraph:
```python
from colorist import BgColor
print(f"I want {BgColor.RED}red{BgColor.OFF} background color inside this paragraph")
print(f"Both {BgColor.GREEN}green{BgColor.OFF} and {BgColor.YELLOW}yellow{BgColor.OFF} are nice background colors")
```
How it appears in the terminal:

```python
from colorist import BgBrightColor
print(f"I want {BgBrightColor.CYAN}cyan{BgBrightColor.OFF} background color inside this paragraph")
```
How it appears in the terminal:

As with text colors, remember to use `BgColor.OFF` or `BgBrightColor.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 often easier and more readable to use [f-strings](https://peps.python.org/pep-0498/) as in the examples above, but f-strings aren't supported in some earlier versions of Python. Instead, you can also use string formatting or concatenation:
```python
from colorist import Color
print("I want {0}red{1} color inside this paragraph".format(Color.RED, Color.OFF))
print("I want " + Color.RED + "red" + Color.OFF + " color inside this paragraph")
```
Both options appear the same in the terminal:

### Print RGB, HSL and Hex Colors
Note that not all terminals support RGB, HSL or Hex colors. If your terminal does support such advanced colors, read on.
#### RGB Colors
Try the `rgb` and `bg_rgb` methods for a full line of colored text. The values for red, green, blue can be an integer between `0-255`.
```python
from colorist import rgb, bg_rgb
rgb("I want this text in blue RGB colors", 0, 128, 255)
bg_rgb("I want this background in blue RGB colors", 0, 128, 255)
```
How it appears in the terminal:

Or customize the styling of text and background with the `ColorRGB` and `BgColorRGB` classes:
```python
from colorist import ColorRGB, BgColorRGB
dusty_pink = ColorRGB(194, 145, 164)
bg_steel_blue = BgColorRGB(70, 130, 180)
print(f"I want to use {dusty_pink}dusty pink{dusty_pink.OFF} and {bg_steel_blue}steel blue{bg_steel_blue.OFF} colors inside this paragraph")
```
How it appears in the terminal:

#### HSL Colors
Similarly, you can also output colors in HSL with the `hsl` and `bg_hsl` methods. The value for hue can be between `0-360` degrees, while saturation and lightness can be a percentage between `0-100` %:
```python
from colorist import hsl, bg_hsl
hsl("I want this text in green HSL colors", 120, 50, 50)
bg_hsl("I want this background in green HSL colors", 120, 50, 50)
```
How it appears in the terminal:

Or customize the styling of text and background with the `ColorHSL` and `BgColorHSL` classes:
```python
from colorist import ColorHSL, BgColorHSL
mustard_green = ColorHSL(60, 56, 43)
bg_steel_gray = BgColorHSL(190, 2, 49)
print(f"I want to use {mustard_green}mustard green{mustard_green.OFF} and {bg_steel_gray}steel blue{bg_steel_gray.OFF} colors inside this paragraph")
```
How it appears in the terminal:

#### Hex Colors
Try the `hex` and `bg_hex` methods for a full line of colored text. Allowed Hex values are, for instance, `#00aaff` or `#0af`, alternatively without the hash sign as `00aaff` or `0af`.
```python
from colorist import hex, bg_hex
hex("I want this text in coral Hex colors", "#ff7f50")
bg_hex("I want this background in coral Hex colors", "#ff7f50")
```
How it appears in the terminal:

Or customize the styling of text and background with the `ColorHex` and `BgColorHex` classes:
```python
from colorist import ColorHex, BgColorHex
watermelon_red = ColorHex("#ff5733")
bg_mint_green = BgColorHex("#99ff99")
print(f"I want to use {watermelon_red}watermelon pink{watermelon_red.OFF} and {bg_mint_green}mint green{bg_mint_green.OFF} colors inside this paragraph")
```
How it appears in the terminal:

### Print Effects and Other Styles
In addition to colors, Colorist can also add effects when you print text in the terminal. How to print a full line of text with effects:
```python
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:
```python
from colorist import Color, effect_blink
effect_blink("This is BLINKING!", Color.CYAN)
```
How it appears in the terminal:

How to customize terminal messages and change effect inside a paragraph:
```python
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:
```python
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")
```
How it appears in the terminal:

Similar to `Color.OFF`, remember to turn off an effect with the relevant reset option (e.g `Effect.BOLD_OFF`, `Effect.DIM_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 Colors and Styles
Colorist is based on [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code), a standard that defines colors, styling and effects for text in terminal windows. Note that most terminals support all color options, but not all:
| Category | Color Options |
| ------------------------------------------------------ | ---------------------------------------------------------------------------- |
| Standard ANSI colors supported by almost all terminals | `Color`, `BgColor`, `Effect` |
| Non-standard ANSI colors supported by most terminals | `BrightColor`, `BgBrightColor` |
| Advanced ANSI colors only supported by some terminals | `ColorRGB`, `BgColorRGB`, `ColorHSL`, `BgColorHSL`, `ColorHex`, `BgColorHex` |
## Foreground Text
| Color | Full Text Function | Custom | Example |
| ----- | ------------------ | ------ | ------- |
|  | `green("text")` | `Color.GREEN` |  |
|  | `yellow("text")` | `Color.YELLOW` |  |
|  | `red("text")` | `Color.RED` |  |
|  | `magenta("text")` | `Color.MAGENTA` |  |
|  | `blue("text")` | `Color.BLUE` |  |
|  | `cyan("text")` | `Color.CYAN` |  |
|  | `white("text")` | `Color.WHITE` |  |
|  | `black("text")` | `Color.BLACK` |  |
| - | - | `Color.DEFAULT` | - |
| - | - | `Color.OFF` | - |
|  | `bright_green("text")` | `BrightColor.GREEN` |  |
|  | `bright_yellow("text")` | `BrightColor.YELLOW` |  |
|  | `bright_red("text")` | `BrightColor.RED` |  |
|  | `bright_magenta("text")` | `BrightColor.MAGENTA` |  |
|  | `bright_blue("text")` | `BrightColor.BLUE` |  |
|  | `bright_cyan("text")` | `BrightColor.CYAN` |  |
|  | `bright_white("text")` | `BrightColor.WHITE` |  |
|  | `bright_black("text")` | `BrightColor.BLACK` |  |
| - | - | `BrightColor.DEFAULT` | - |
| - | - | `BrightColor.OFF` | - |
## Background
| Color | Full Text Function | Custom | Example |
| ----- | ------------------ | ------ | ------- |
|  | `bg_green("text")` | `BgColor.GREEN` |  |
|  | `bg_yellow("text")` | `BgColor.YELLOW` |  |
|  | `bg_red("text")` | `BgColor.RED` |  |
|  | `bg_magenta("text")` | `BgColor.MAGENTA` |  |
|  | `bg_blue("text")` | `BgColor.BLUE` |  |
|  | `bg_cyan("text")` | `BgColor.CYAN` |  |
|  | `bg_white("text")` | `BgColor.WHITE` |  |
|  | `bg_black("text")` | `BgColor.BLACK` |  |
| - | - | `BgColor.DEFAULT` | - |
| - | - | `BgColor.OFF` | - |
|  | `bg_bright_green("text")` | `BgBrightColor.GREEN` |  |
|  | `bg_bright_yellow("text")` | `BgBrightColor.YELLOW` |  |
|  | `bg_bright_red("text")` | `BgBrightColor.RED` |  |
|  | `bg_bright_magenta("text")` | `BgBrightColor.MAGENTA` |  |
|  | `bg_bright_blue("text")` | `BgBrightColor.BLUE` |  |
|  | `bg_bright_cyan("text")` | `BgBrightColor.CYAN` |  |
|  | `bg_bright_white("text")` | `BgBrightColor.WHITE` |  |
|  | `bg_bright_black("text")` | `BgBrightColor.BLACK` |  |
| - | - |`BgBrightColor.DEFAULT` | - |
| - | - | `BgBrightColor.OFF` | - |
## Effects
| Effect | Full Text Function | Custom | Reset | Example |
| ---------------- | -------------------------- | ------------------ | ---------------------- | ---------- |
| **Bold** | `effect_bold("text")` | `Effect.BOLD` | `Effect.BOLD_OFF` |  |
| Dim | `effect_dim("text")` | `Effect.DIM` | `Effect.DIM_OFF` |  |
| <u>Underline</u> | `effect_underline("text")` | `Effect.UNDERLINE` | `Effect.UNDERLINE_OFF` |  |
| Blink | `effect_blink("text")` | `Effect.BLINK` | `Effect.BLINK_OFF` |  |
| Reverse | `effect_reverse("text")` | `Effect.REVERSE` | `Effect.REVERSE_OFF` |  |
| Hide | `effect_hide("text")` | `Effect.HIDE` | `Effect.HIDE_OFF` |  |
| - | - | - | `Effect.OFF` | - |
# Thank You for Supporting
## Donate
This module is free to use. And if you like it, feel free to [buy me a coffee](https://github.com/sponsors/jakob-bagterp).
## Contribute
If you have suggestions or changes to the module, feel free to add to the code and create a [pull request](https://github.com/jakob-bagterp/colorist-for-python/pulls).
## Report Bugs
Report bugs and issues [here](https://github.com/jakob-bagterp/colorist-for-python/issues).
[](https://github.com/jakob-bagterp/colorist-for-python/releases/latest)

[](https://github.com/jakob-bagterp/colorist-for-python/blob/master/LICENSE.md)
[](https://codecov.io/gh/jakob-bagterp/colorist-for-python)
[](https://github.com/jakob-bagterp/colorist-for-python/actions/workflows/test.yml)
# 🌈 How to Install Colorist for Python 🌈
## Prerequisites
* Python version:
* 2.7
* 3.10, 3.11 or higher
* Terminal that supports color (i.e. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code))
## Installation
### PyPI
Assuming that Python is installed already, execute this command in the terminal:
```shell
pip install colorist
```
If you already have installed Colorist for Python, use this command to upgrade to latest version:
```shell
pip install --upgrade colorist
```
### Homebrew
If you already have installed the [Homebrew](https://brew.sh) package manager for Mac and Linux, execute this terminal command to tap Colorist for Python:
```shell
brew tap jakob-bagterp/colorist
```
And then install:
```shell
brew install colorist
```
## Getting Started
Ready to go? [Learn how to use Colorist](https://github.com/jakob-bagterp/colorist-for-python/blob/master/README.md).
# 3-Clause BSD License
Copyright (c) 2022 – present, Jakob Bagterp
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.