Skip to main content

Python 3 Colorful Print Functions 🌈🖨️

These Python functions allow you to print text with various colors and styles in your terminal. Spice up your console output with these vibrant options! 🎨

With these functions, you can make your terminal output more engaging and colorful. Experiment with different colors and styles to create visually appealing text. 😊🚀

Note: To ensure the proper functionality of these functions, it is important that your terminal supports the ANSI standard for colored text formatting. Make sure your console is ANSI-compatible before using these functions to achieve the desired effect.

Supported Python Versions

  • Python 3.6+

Installing

If you have pip on your system, you can simply install or upgrade the Python Module:

pip install -U python_print_color


Usage

To import the functions inside teh package simply use from python_print_color import * as shown in the example:

from python_print_color import *

print_color_8bits("8 Bit colored text example", foreground="red", background="white", styles=["italic", "underline"])
print_color_rgb("RGB colored text example", foreground=(0, 128, 128), background=(0, 0, 128), styles=["underline"])

Function: Print Color 8 Bits

print_color_8bits prints text using 8-bit color codes and optional text styles.

def print_color_8bits(text, foreground="reset", background="reset", styles=[]):
    """
    Print colored text using 8-bit color codes and optional text styles.

    Parameters:
    - text (str): The text to be colored.
    - foreground (str, optional): The foreground color name or code (default is "reset").
    - background (str, optional): The background color name or code (default is "reset").
    - styles (list, optional): A list of text styles to apply (e.g., ["bold", "italic"]).

    Color and style codes are specified using string names or codes.
    Supported color names: "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "default", "reset".
    Supported style names: "bold", "dim", "italic", "underline", "blink", "reverse", "hidden", "strikethrough".
    """
Example Usage (8-bit Colors):
# Example 1: Print 8-bit colored text with bold style and a custom background color (e.g., green)
print_color_8bits("Bold text with green background", foreground="white", background="green", styles=["bold"])

# Example 2: Print 8-bit colored text with italic style and a custom foreground color (e.g., yellow)
print_color_8bits("Italic text with yellow foreground", foreground="yellow", styles=["italic"])

# Example 3: Print 8-bit colored text with underline style, a custom foreground color (e.g., red),
# and a custom background color (e.g., blue)
print_color_8bits("Underlined text with red foreground and blue background", foreground="red", background="blue", styles=["underline"])

Function: Print Color RGB 🌟

print_color_rgb prints text using RGB color codes and optional text styles.

def print_color_rgb(text, foreground=None, background=None, styles=[]):
    """
    Print colored text using RGB color codes and optional text styles.

    Parameters:
    - text (str): The text to be colored.
    - foreground (tuple, optional): RGB values for the foreground color (default is None).
    - background (tuple, optional): RGB values for the background color (default is None).
    - styles (list, optional): A list of text styles to apply (e.g., ["bold", "italic"]).

    RGB values are specified as tuples with three integers in the range 0-255.
    Supported style names: "bold", "dim", "italic", "underline", "blink", "reverse", "hidden", "strikethrough".
    """
Example Usage (RGB Colors):
# Example 4: Print RGB colored text with bold style and a custom background color (e.g., purple)
print_color_rgb("Bold text with purple background", foreground=(255, 255, 255), background=(128, 0, 128), styles=["bold"])

# Example 5: Print RGB colored text with italic style and a custom foreground color (e.g., orange)
print_color_rgb("Italic text with orange foreground", foreground=(255, 165, 0), styles=["italic"])

# Example 6: Print RGB colored text with underline style, a custom foreground color (e.g., teal),
# and a custom background color (e.g., navy blue)
print_color_rgb("Underlined text with teal foreground and navy blue background", foreground=(0, 128, 128), background=(0, 0, 128), styles=["underline"])

Metadata

Release files for python-print-color 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-print-color 0.0.2
File Size Uploaded
python_print_color-0.0.2.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for python-print-color 0.0.2
File Interpreter ABI Platform
python_print_color-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / python_print_color-0.0.2.tar.gz

Download URL python_print_color-0.0.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
d2fb4220b20241f82b17f97934619ced51955888d1b856342d4e31cff8fdd438
BLAKE2b-256 checksum
How to use checksums
572399bb3f5231b928280b3b110b0f4680644d54031e9b9ec8b55d1552e4e3ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Release files / python_print_color-0.0.2-py3-none-any.whl

Download URL python_print_color-0.0.2-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c74a786bc47387cd1d18cee631ec0fc76b295f4d9678e65baf0bdfcf956d3be9
BLAKE2b-256 checksum
How to use checksums
81e1411070ee7ee796f54da9e97dd3378e5b463acd50db8019c5078b77d46a73
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page