New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

colorist

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colorist

Colorist for Python

  • 1.8.3
  • PyPI
  • Socket score

Maintainers
1

Latest version Python 3.10 | 3.11 | 3.12 | 3.13+ BSD-3-Clause license Codecov CodeQL Test Downloads

🌈 Colorist for Python 🌈

Lightweight Python package that makes it easy and fast to print colored text in the terminal.

Ready to try? See how to install.

Getting Started

Print Line of Colored Text

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:

Example of full line of green, yellow, red colored text printed in a terminal window

Print Mixed Text Colors

How to customize colors inside a paragraph and print it in the terminal:

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:

Example of white text mixed with green, yellow, red colors printed in a terminal window

Other Styling Options

Print Bright Colors

Most terminals support bright colors that stand more out:

from colorist import BrightColor

print(f"I want {BrightColor.CYAN}cyan{BrightColor.OFF} color inside this paragraph")

How it appears in the terminal:

Example of white text mixed with cyan printed in a terminal window

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

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:

Example of white text and colored backgrounds if green, yellow, red printed in a terminal window

Background colors can also be mixed 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:

Example of black, green, yellow, red background colors mixed inside paragraph printed in a terminal window

from colorist import BgBrightColor

print(f"I want {BgBrightColor.CYAN}cyan{BgBrightColor.OFF} background color inside this paragraph")

How it appears in the terminal:

Example of white text on a cyan background color printed in a terminal window

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.

Foreground Text

ColorFull Text FunctionCustomExample
Greengreen("text")Color.GREENGreen text color in terminal
Yellowyellow("text")Color.YELLOWYellow text color in terminal
Redred("text")Color.REDRed text color in terminal
Magentamagenta("text")Color.MAGENTAMagenta text color in terminal
Blueblue("text")Color.BLUEBlue text color in terminal
Cyancyan("text")Color.CYANCyan text color in terminal
Whitewhite("text")Color.WHITEWhite text color in terminal
Blackblack("text")Color.BLACKBlack text color in terminal
--Color.DEFAULT-
--Color.OFF-
Bright greenbright_green("text")BrightColor.GREENBright green text color in terminal
Bright yellowbright_yellow("text")BrightColor.YELLOWBright yellow text color in terminal
Bright redbright_red("text")BrightColor.REDBright red text color in terminal
Bright magentabright_magenta("text")BrightColor.MAGENTABright magenta text color in terminal
Bright bluebright_blue("text")BrightColor.BLUEBright blue text color in terminal
Bright cyanbright_cyan("text")BrightColor.CYANBright cyan text color in terminal
Bright whitebright_white("text")BrightColor.WHITEBright white text color in terminal
Bright blackbright_black("text")BrightColor.BLACKBright black text color in terminal
--BrightColor.DEFAULT-
--BrightColor.OFF-

Background

ColorFull Text FunctionCustomExample
Greenbg_green("text")BgColor.GREENGreen background color in terminal
Yellowbg_yellow("text")BgColor.YELLOWYellow background color in terminal
Redbg_red("text")BgColor.REDRed background color in terminal
Magentabg_magenta("text")BgColor.MAGENTAMagenta background color in terminal
Bluebg_blue("text")BgColor.BLUEBlue background color in terminal
Cyanbg_cyan("text")BgColor.CYANCyan background color in terminal
Whitebg_white("text")BgColor.WHITEWhite background color in terminal
Blackbg_black("text")BgColor.BLACKBlack background color in terminal
--BgColor.DEFAULT-
--BgColor.OFF-
Bright greenbg_bright_green("text")BgBrightColor.GREENBright green background color in terminal
Bright yellowbg_bright_yellow("text")BgBrightColor.YELLOWBright yellow background color in terminal
Bright redbg_bright_red("text")BgBrightColor.REDBright red background color in terminal
Bright magentabg_bright_magenta("text")BgBrightColor.MAGENTABright magenta background color in terminal
Bright bluebg_bright_blue("text")BgBrightColor.BLUEBright blue background color in terminal
Bright cyanbg_bright_cyan("text")BgBrightColor.CYANBright cyan background color in terminal
Bright whitebg_bright_white("text")BgBrightColor.WHITEBright white background color in terminal
Bright blackbg_bright_black("text")BgBrightColor.BLACKBright black background color in terminal
--BgBrightColor.DEFAULT-
--BgBrightColor.OFF-

Thank You for Supporting

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.

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.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc