color

Use enum.Enum to store color with hex, rgb, bgr format.

source

Color

 Color (value, names=None, module=None, qualname=None, type=None, start=1)

Use enum.Enum to store color with hex, rgb, bgr format.

Color.red.name, Color.red.hex, Color.red.rgb
('red', '#ff0000', (255, 0, 0))

Here are Color.available:

Code
def _get_background(color):
    background = (
        Back['75, 70, 75'] 
        if sum(Color[color].rgb) / 3 > 165 else 
        Back['240, 250, 250']
    )
    return background


for i, c in enumerate(Fore.available):
    background = _get_background(c)
    print(background, end='')
    end = '\n' if (i+1) % 4 == 0 else '\t'
    print(f'{Fore[c]}{c:21s}{Fore.reset}', end=end)
print(Back.reset_all)

You can also use it with matplotlib.pyplot:

plt.plot(range(5), color=Color.red.hex)

/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/fastcore/docscrape.py:225: UserWarning: Unknown section Examples
  else: warn(msg)

source

rgb2hex

 rgb2hex (r:int, g:int, b:int)

convert rgb color to hex

rgb = (255, 255, 255)
rgb2hex(*rgb), rgb2hex(43, 159, 225)
('#ffffff', '#2b9fe1')

source

hex2rgb

 hex2rgb (h:str)

convert hex color to rgb tuple

hex2rgb('#ffffff'), hex2rgb('#1af1eb')
((255, 255, 255), (26, 241, 235))