Colorist for Python
Project description
🌈 Colorist for Python 🌈
Lightweight Python package that makes it easy and fast to print terminal messages in colors.
Prerequisites
- Python 3.10 or higher
Installation
PyPI
Assuming that Python is installed already, execute this command in the terminal:
pip3 install colorist
If you already have installed Colorist for Python, use this command to upgrade to latest version:
pip3 install --upgrade colorist
Homebrew
If you already have installed the Homebrew package manager for Mac and Linux, execute this terminal command to tap Colorist for Python:
brew tap jakob-bagterp/colorist
And then install:
brew install colorist
Text 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
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.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.OFF |
- |
Background Colors
Getting Started
Full Terminal Output
How to print a full line of text with colored background in the terminal:
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:
Custom Terminal Output
How to customize terminal messages and change background color inside a paragraph:
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:
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.
Supported Background Colors
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.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.OFF |
- |
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")
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 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 |
|
Underline | 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 |
- |
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.
MIT License
Copyright (c) 2022 – present Jakob Bagterp
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file colorist-1.2.2.tar.gz
.
File metadata
- Download URL: colorist-1.2.2.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb6541a7a1e2518094b52b789680c99008b84a357cf30cb8965413e817e02c3b |
|
MD5 | 383abd263ad8482c4d396201e7a4cfde |
|
BLAKE2b-256 | 3682a329c02d87b8637f885d7bb6a8d39f18112c906661318f5eacf1a0942901 |
File details
Details for the file colorist-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: colorist-1.2.2-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc86f0307615fc07a2c36331b64afa78e343f06716f755927f417ec63b49a328 |
|
MD5 | 27f14ff513a70aa92d1ae8b177e9fd9a |
|
BLAKE2b-256 | a8c0fbfd92843ab03bfb9873e6c501a659c86a262d3da38a9f403c5c3c1c7ce7 |