Getting Started

Color: Color strings based on the ansicolors package.

Create a color by ID:

from colorpalette import *
green = Color('forestgreen')

Color a string:

print(green('This is green'))
This is green

Colors can also be concatenated. Add Color.reset, to remove the color code in later strings

print(green + 'This is green' + Color.reset + '\nThis is normal')
This is green
This is normal

You can also create a color passing the foreground color (fg), background color (bg), style, and define them with an ID.

green_lavender = Color(fg='forestgreen', bg='lavenderblush', style='underline', ID='green_lavender')

Note: Please refer to the color function in the ansicolors package for further details on these parameters:

All colors with an ID are saved in ‘cached’:

{'aliceblue': aliceblue,
 'antiquewhite': antiquewhite,
 'aqua': aqua,
 'aquamarine': aquamarine,
 'azure': azure,
 'beige': beige,
 'bisque': bisque,
 'black': black,
 'blanchedalmond': blanchedalmond,
 'blue': blue,
 'blueviolet': blueviolet,
 'brown': brown,
 'burlywood': burlywood,
 'cadetblue': cadetblue,
 'chartreuse': chartreuse,
 'chocolate': chocolate,
 'coral': coral,
 'cornflowerblue': cornflowerblue,
 'cornsilk': cornsilk,
 'crimson': crimson,
 'cyan': cyan,
 'darkblue': darkblue,
 'darkcyan': darkcyan,
 'darkgoldenrod': darkgoldenrod,
 'darkgray': darkgray,
 'darkgreen': darkgreen,
 'darkgrey': darkgrey,
 'darkkhaki': darkkhaki,
 'darkmagenta': darkmagenta,
 'darkolivegreen': darkolivegreen,
 'darkorange': darkorange,
 'darkorchid': darkorchid,
 'darkred': darkred,
 'darksalmon': darksalmon,
 'darkseagreen': darkseagreen,
 'darkslateblue': darkslateblue,
 'darkslategray': darkslategray,
 'darkslategrey': darkslategrey,
 'darkturquoise': darkturquoise,
 'darkviolet': darkviolet,
 'deeppink': deeppink,
 'deepskyblue': deepskyblue,
 'dimgray': dimgray,
 'dimgrey': dimgrey,
 'dodgerblue': dodgerblue,
 'firebrick': firebrick,
 'floralwhite': floralwhite,
 'forestgreen': forestgreen,
 'fuchsia': fuchsia,
 'gainsboro': gainsboro,
 'ghostwhite': ghostwhite,
 'gold': gold,
 'goldenrod': goldenrod,
 'gray': gray,
 'green': green,
 'greenyellow': greenyellow,
 'grey': grey,
 'honeydew': honeydew,
 'hotpink': hotpink,
 'indianred': indianred,
 'indigo': indigo,
 'ivory': ivory,
 'khaki': khaki,
 'lavender': lavender,
 'lavenderblush': lavenderblush,
 'lawngreen': lawngreen,
 'lemonchiffon': lemonchiffon,
 'lightblue': lightblue,
 'lightcoral': lightcoral,
 'lightcyan': lightcyan,
 'lightgoldenrodyellow': lightgoldenrodyellow,
 'lightgray': lightgray,
 'lightgreen': lightgreen,
 'lightgrey': lightgrey,
 'lightpink': lightpink,
 'lightsalmon': lightsalmon,
 'lightseagreen': lightseagreen,
 'lightskyblue': lightskyblue,
 'lightslategray': lightslategray,
 'lightslategrey': lightslategrey,
 'lightsteelblue': lightsteelblue,
 'lightyellow': lightyellow,
 'lime': lime,
 'limegreen': limegreen,
 'linen': linen,
 'magenta': magenta,
 'maroon': maroon,
 'mediumaquamarine': mediumaquamarine,
 'mediumblue': mediumblue,
 'mediumorchid': mediumorchid,
 'mediumpurple': mediumpurple,
 'mediumseagreen': mediumseagreen,
 'mediumslateblue': mediumslateblue,
 'mediumspringgreen': mediumspringgreen,
 'mediumturquoise': mediumturquoise,
 'mediumvioletred': mediumvioletred,
 'midnightblue': midnightblue,
 'mintcream': mintcream,
 'mistyrose': mistyrose,
 'moccasin': moccasin,
 'navajowhite': navajowhite,
 'navy': navy,
 'oldlace': oldlace,
 'olive': olive,
 'olivedrab': olivedrab,
 'orange': orange,
 'orangered': orangered,
 'orchid': orchid,
 'palegoldenrod': palegoldenrod,
 'palegreen': palegreen,
 'paleturquoise': paleturquoise,
 'palevioletred': palevioletred,
 'papayawhip': papayawhip,
 'peachpuff': peachpuff,
 'peru': peru,
 'pink': pink,
 'plum': plum,
 'powderblue': powderblue,
 'purple': purple,
 'rebeccapurple': rebeccapurple,
 'red': red,
 'rosybrown': rosybrown,
 'royalblue': royalblue,
 'saddlebrown': saddlebrown,
 'salmon': salmon,
 'sandybrown': sandybrown,
 'seagreen': seagreen,
 'seashell': seashell,
 'sienna': sienna,
 'silver': silver,
 'skyblue': skyblue,
 'slateblue': slateblue,
 'slategray': slategray,
 'slategrey': slategrey,
 'snow': snow,
 'springgreen': springgreen,
 'steelblue': steelblue,
 'tan': tan,
 'teal': teal,
 'thistle': thistle,
 'tomato': tomato,
 'turquoise': turquoise,
 'violet': violet,
 'wheat': wheat,
 'white': white,
 'whitesmoke': whitesmoke,
 'yellow': yellow,
 'yellowgreen': yellowgreen,
 'reset': reset,
 'green_lavender': green_lavender}

Get RGB or HEX of the Color object:

# Foreground color (RGB)
array([ 34., 139.,  34.])
# Foreground color (normalized RGB)
array([0.13333333, 0.54509804, 0.13333333])
# Background color (RGB)
array([255., 240., 245.])
# Background color (normalized RGB)
array([1.        , 0.94117647, 0.96078431])
# Foreground color (HEX)
# Background color (HEX)

Get tints and shades of the Color object:

green_lavender.tint(25) # 25% tint
25% tinted green_lavender
green_lavender.shade(25) # 25% shade
25% shaded green_lavender

Palette: Iterable set of named Color objects.

Create a Palette object with key/Color pairs:

color_scheme = Palette(string=green, emphasis=green_lavender, warning=Color('red'))
Palette(string, emphasis, warning)

All Color objects are attributes:

color_scheme.string, color_scheme.emphasis, color_scheme.warning

Palette objects are iterable:

for color in color_scheme: