API Reference

This section provides complete API documentation for all classes, functions, and methods in Colorium.

Overview

ModuleDescription
ColorCore Color class
Color SpacesSpace-specific functions
FiltersFilter classes and presets
UtilitiesUtility functions
ConstantsNamed colors and constants

Color Class

Constructor

1
Color(red: int, green: int, blue: int, opacity: float = 1.0)

Creates a new Color instance.

ParameterTypeRangeDescription
redint0-255Red component
greenint0-255Green component
blueint0-255Blue component
opacityfloat0-1Opacity (default: 1.0)

Example:

1
2
3
4
from colorium import Color

red = Color(255, 0, 0)
transparent_red = Color(255, 0, 0, 0.5)

Properties

RGB Properties

PropertyTypeDescription
redintRed component (0-255)
greenintGreen component (0-255)
blueintBlue component (0-255)
opacityfloatOpacity (0-1)

Example:

1
2
3
4
5
6
7
8
9
10
11
from colorium import Color

color = Color(100, 150, 200)
print(color.red)      # 100
print(color.green)    # 150
print(color.blue)     # 200
print(color.opacity)  # 1.0

color.red = 255
color.green = 0
color.blue = 0

HSL Properties

PropertyTypeDescription
huefloatHue angle (0-360)
satfloatSaturation (0-1)
lightnessfloatLightness (0-1)

Example:

1
2
3
4
5
6
from colorium import Color

color = Color(255, 0, 0)
print(color.hue)        # 0
print(color.sat)        # 1.0
print(color.lightness)  # 0.5

HWB Properties

PropertyTypeDescription
whitenessfloatWhiteness (0-1)
blacknessfloatBlackness (0-1)

Example:

1
2
3
4
5
from colorium import Color

color = Color(255, 0, 0)
print(color.whiteness)  # 0.0
print(color.blackness)  # 0.0

CMYK Properties

PropertyTypeDescription
cyanfloatCyan (0-1)
magentafloatMagenta (0-1)
yellowfloatYellow (0-1)
blackfloatBlack (0-1)

Example:

1
2
3
4
5
6
7
from colorium import Color

color = Color(255, 0, 0)
print(color.cyan)     # 0.0
print(color.magenta)  # 1.0
print(color.yellow)   # 1.0
print(color.black)    # 0.0

String Methods

MethodReturnsExample
to_rgb_string()strrgb(255, 0, 0)
to_rgba_string()strrgba(255, 0, 0, 1.00)
to_hsl_string()strhsl(0, 100%, 50%)
to_hsla_string()strhsla(0, 100%, 50%, 1.00)
to_hwb_string()strhwb(0, 0%, 0%)
to_hwba_string()strhwba(0, 0%, 0%, 1.00)
to_cmyk_string()strcmyk(0%, 100%, 100%, 0%)
to_hex_string()str#FF0000
to_oklch_string()stroklch(62.8% 0.258 29.2)
to_lab_string()strlab(53.2% 80.1 67.2)
to_lch_string()strlch(53.2% 104.5 40.0)
to_p3_string()strcolor(display-p3 0.823 0.033 0.017)
to_ncol_string()strncol(R0, 0%, 0%)
to_name()strRed

Example:

1
2
3
4
5
6
7
from colorium import Color

color = Color(255, 0, 0)
print(color.to_rgb_string())    # rgb(255, 0, 0)
print(color.to_hex_string())    # #FF0000
print(color.to_hsl_string())    # hsl(0, 100%, 50%)
print(color.to_name())          # Red

Dictionary Methods

MethodReturnsKeys
to_rgb()Dictr, g, b, a
to_hsl()Dicth, s, l, a
to_hwb()Dicth, w, b, a
to_cmyk()Dictc, m, y, k, a
to_oklch()Dictl, c, h
to_lab()Dictl, a, b
to_lch()Dictl, c, h
to_p3()Dictr, g, b
to_ncol()Dictncol, w, b, a

Example:

1
2
3
4
5
6
7
8
from colorium import Color

color = Color(255, 0, 0)
rgb = color.to_rgb()
print(rgb['r'])  # 255
print(rgb['g'])  # 0
print(rgb['b'])  # 0
print(rgb['a'])  # 1.0

Manipulation Methods

MethodDescription
lighter(amount)Increase lightness
darker(amount)Decrease lightness
saturate(amount)Increase saturation
desaturate(amount)Decrease saturation
blend(other, ratio)Blend with another color
clone()Create a copy
is_dark(threshold)Check if color is dark

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from colorium import Color

color = Color(100, 150, 200)

# Manipulate
color.lighter(0.2)
color.darker(0.1)
color.saturate(0.3)

# Clone
copy = color.clone()

# Check
print(color.is_dark())  # False

# Blend
other = Color(255, 0, 0)
blended = color.blend(other, 0.5)

Distance Methods

MethodDescription
delta_e(other, method)Calculate Delta E
similarity(other, method)Calculate similarity
is_similar_to(other, threshold, method)Check similarity

Methods: "cie76", "cie94", "cie2000"

Example:

1
2
3
4
5
6
7
8
9
10
from colorium import Color

color1 = Color(100, 150, 200)
color2 = Color(120, 130, 180)

distance = color1.delta_e(color2, "cie2000")
similarity = color1.similarity(color2)

if color1.is_similar_to(color2, threshold=0.8):
    print("Similar")

Factory Functions

From Strings

FunctionDescription
from_string(color_str)Parse any color string
from_hex(hex_str)Create from hex string

Supported formats: named colors, hex, RGB, HSL, HWB, CMYK, NCOL

Example:

1
2
3
4
5
from colorium import from_string, from_hex

red = from_string("red")
hex_color = from_hex("#FF0000")
hsl_color = from_string("hsl(0, 100%, 50%)")

From Color Spaces

FunctionDescription
from_rgb(r, g, b, opacity)Create from RGB
from_hsl(h, s, l, opacity)Create from HSL
from_hwb(h, w, b, opacity)Create from HWB
from_cmyk(c, m, y, k, opacity)Create from CMYK
from_oklch(l, c, h, opacity)Create from OKLCH
from_lab(l, a, b, opacity)Create from LAB
from_lch(l, c, h, opacity)Create from LCH
from_p3(r, g, b, opacity)Create from Display P3

Example:

1
2
3
4
from colorium import from_hsl, from_cmyk

hsl_color = from_hsl(200, 0.8, 0.5)
cmyk_color = from_cmyk(0, 1.0, 1.0, 0)

Color Filters

Filter Classes

FilterConstructorDescription
SepiaFilterintensity=1.0Sepia effect
GrayscaleFiltermethod="luminance"Grayscale conversion
InvertFilterNoneNegative effect
ContrastFilteramount=1.2Contrast adjustment
BrightnessFilteramount=1.2Brightness adjustment
SaturationFilteramount=0.5Saturation adjustment
HueRotateFilterdegrees=90Hue rotation
PosterizeFilterlevels=4Posterize effect
TemperatureFilterkelvin=5500Temperature adjustment
VignetteFilterintensity=0.5Vignette effect

Example:

1
2
3
4
5
6
7
8
9
from colorium import SepiaFilter, InvertFilter, FilterPresets

# Single filter
sepia = SepiaFilter(0.7)
result = sepia(color)

# Preset
clarendon = FilterPresets.clarendon()
result = clarendon(color)

Filter Presets

MethodDescription
FilterPresets.clarendon()Vibrant punchy look
FilterPresets.gingham()Warm soft vintage
FilterPresets.moon()High-contrast black and white
FilterPresets.lark()Cool vibrant modern
FilterPresets.toaster()Warm retro vintage
FilterPresets.valencia()Warm soft vintage
FilterPresets.amaro()Rich warm slightly dark

Composite Filter

MethodDescription
CompositeFilter(filters, name)Chain multiple filters
add_filter(filter)Add filter to chain

Example:

1
2
3
4
5
6
7
from colorium import CompositeFilter, SepiaFilter, ContrastFilter

vintage = CompositeFilter([
    SepiaFilter(0.5),
    ContrastFilter(1.1)
])
result = vintage(color)

Utility Functions

FunctionDescription
is_hex(char)Check if character is valid hex
clamp(value, min, max)Clamp value to range
to_hex(value)Convert to hex string
parse_percentage(value)Parse percentage string
trim_string(value)Trim whitespace

Example:

1
2
3
4
from colorium.utils import clamp, to_hex

clamped = clamp(1.5, 0, 1)  # 1.0
hex_str = to_hex(255)       # FF

Constants

Color Constants

ConstantValue
REDColor(255, 0, 0)
GREENColor(0, 255, 0)
BLUEColor(0, 0, 255)
WHITEColor(255, 255, 255)
BLACKColor(0, 0, 0)
GRAYColor(128, 128, 128)

Named Colors

ListDescription
COLOR_NAMESList of all 147 CSS named colors
COLOR_HEXESCorresponding hex values
NAMED_COLORSCase-insensitive mapping

Example:

1
2
3
4
from colorium import COLOR_NAMES, NAMED_COLORS

print(COLOR_NAMES[0])        # AliceBlue
print(NAMED_COLORS['red'])   # ff0000

Exceptions

ExceptionDescription
ValueErrorInvalid color values
TypeErrorInvalid color types
AttributeErrorInvalid attribute access

Type Hints

All functions have complete type hints for better IDE support:

1
2
3
4
5
def lighter(self, amount: float = 0.1) -> None:
    pass

def blend(self, other: 'Color', ratio: float = 0.5) -> 'Color':
    pass

Next Steps


Previous: Contributing Next: Color Class →

On this page
26 sections