catppuccin.models

Dataclass definitions for the Catppuccin palette data structure.

  1"""Dataclass definitions for the Catppuccin palette data structure."""
  2
  3from collections.abc import Iterator
  4from dataclasses import dataclass
  5from enum import StrEnum
  6from typing import cast
  7
  8__all__ = [
  9    "Palette",
 10    "Flavor",
 11    "FlavorColors",
 12    "Color",
 13    "RGB",
 14    "HSL",
 15    "FlavorName",
 16    "ColorName",
 17]
 18
 19
 20class FlavorName(StrEnum):
 21    """Identifiers of the flavors, in palette order."""
 22
 23    LATTE = "latte"
 24    FRAPPE = "frappe"
 25    MACCHIATO = "macchiato"
 26    MOCHA = "mocha"
 27
 28
 29class ColorName(StrEnum):
 30    """Identifiers of the colors in a flavor, in palette order."""
 31
 32    ROSEWATER = "rosewater"
 33    FLAMINGO = "flamingo"
 34    PINK = "pink"
 35    MAUVE = "mauve"
 36    RED = "red"
 37    MAROON = "maroon"
 38    PEACH = "peach"
 39    YELLOW = "yellow"
 40    GREEN = "green"
 41    TEAL = "teal"
 42    SKY = "sky"
 43    SAPPHIRE = "sapphire"
 44    BLUE = "blue"
 45    LAVENDER = "lavender"
 46    TEXT = "text"
 47    SUBTEXT1 = "subtext1"
 48    SUBTEXT0 = "subtext0"
 49    OVERLAY2 = "overlay2"
 50    OVERLAY1 = "overlay1"
 51    OVERLAY0 = "overlay0"
 52    SURFACE2 = "surface2"
 53    SURFACE1 = "surface1"
 54    SURFACE0 = "surface0"
 55    BASE = "base"
 56    MANTLE = "mantle"
 57    CRUST = "crust"
 58
 59
 60@dataclass(frozen=True)
 61class RGB:
 62    """Color represented as red, green, and blue (all 0-255)."""
 63
 64    r: int
 65    """@public"""
 66    g: int
 67    """@public"""
 68    b: int
 69    """@public"""
 70
 71
 72@dataclass(frozen=True)
 73class HSL:
 74    """Color represented as hue (0-359), saturation (0-1), and lightness (0-1)."""
 75
 76    h: float
 77    """@public"""
 78    s: float
 79    """@public"""
 80    l: float  # noqa: E741
 81    """@public"""
 82
 83
 84@dataclass(frozen=True)
 85class Color:
 86    """A single color in the Catppuccin palette."""
 87
 88    name: str
 89    """A human-readable name such as `Pink` or `Surface0`."""
 90    identifier: str
 91    """The lowercase key used to identify the color. This differs from `name` in
 92    that it's intended for machine usage rather than presentation."""
 93    accent: bool
 94    """Whether the color is considered an accent color. Accent colors are the
 95    first 14 colors in the palette, also called the analogous colours. The
 96    remaining 12 non-accent colors are also referred to as the monochromatic
 97    colors."""
 98    order: int
 99    """Order of the color in the palette spec."""
100    hex: str
101    """The color represented as a six-digit hex string with a leading hash (#)."""
102    rgb: RGB
103    """The color represented as individual red, green, and blue channels. (0-255)"""
104    hsl: HSL
105    """The color represented as individual hue (0-359), saturation (0-1), and
106    lightness (0-1) channels."""
107
108
109@dataclass(frozen=True)
110class FlavorColors:
111    """All of the colors for a particular flavor of Catppuccin.
112
113    Can be iterated over, in which case the colors are yielded in order.
114
115    Colors can also be looked up by identifier, such as `colors["red"]` or
116    `colors[ColorName.RED]`.
117    """
118
119    rosewater: Color
120    """@public"""
121    flamingo: Color
122    """@public"""
123    pink: Color
124    """@public"""
125    mauve: Color
126    """@public"""
127    red: Color
128    """@public"""
129    maroon: Color
130    """@public"""
131    peach: Color
132    """@public"""
133    yellow: Color
134    """@public"""
135    green: Color
136    """@public"""
137    teal: Color
138    """@public"""
139    sky: Color
140    """@public"""
141    sapphire: Color
142    """@public"""
143    blue: Color
144    """@public"""
145    lavender: Color
146    """@public"""
147    text: Color
148    """@public"""
149    subtext1: Color
150    """@public"""
151    subtext0: Color
152    """@public"""
153    overlay2: Color
154    """@public"""
155    overlay1: Color
156    """@public"""
157    overlay0: Color
158    """@public"""
159    surface2: Color
160    """@public"""
161    surface1: Color
162    """@public"""
163    surface0: Color
164    """@public"""
165    base: Color
166    """@public"""
167    mantle: Color
168    """@public"""
169    crust: Color
170    """@public"""
171
172    def __iter__(self) -> Iterator[Color]:
173        """Iterate over colors in the flavor."""
174        yield from [
175            self.rosewater,
176            self.flamingo,
177            self.pink,
178            self.mauve,
179            self.red,
180            self.maroon,
181            self.peach,
182            self.yellow,
183            self.green,
184            self.teal,
185            self.sky,
186            self.sapphire,
187            self.blue,
188            self.lavender,
189            self.text,
190            self.subtext1,
191            self.subtext0,
192            self.overlay2,
193            self.overlay1,
194            self.overlay0,
195            self.surface2,
196            self.surface1,
197            self.surface0,
198            self.base,
199            self.mantle,
200            self.crust,
201        ]
202
203    def __getitem__(self, name: str) -> Color:
204        """Look up a color by identifier, such as `"red"` or `ColorName.RED`.
205
206        Raises `KeyError` if there is no color with that identifier.
207        """
208        try:
209            identifier = ColorName(name)
210        except ValueError:
211            raise KeyError(name) from None
212        return cast(Color, getattr(self, identifier))
213
214
215@dataclass(frozen=True)
216class Flavor:
217    """A flavor is a collection of colors.
218
219    Catppuccin has four flavors; Latte, Frappé, Macchiato, and Mocha.
220    """
221
222    name: str
223    """A human-readable name such as `Latte` or `Mocha`."""
224    identifier: str
225    """The lowercase key used to identify the flavor. This differs from `name`
226    in that it's intended for machine usage rather than presentation"""
227    order: int
228    """Order of the flavor in the palette spec."""
229    dark: bool
230    """Whether this flavor is dark or light oriented. Latte is light, the other
231    three flavors are dark."""
232    colors: FlavorColors
233    """@public"""
234
235
236@dataclass(frozen=True)
237class Palette:
238    """The top-level type that encompasses the Catppuccin palette data structure.
239
240    Primarily used via the `PALETTE` constant.
241    Can be iterated over, in which case the flavors are yielded in the canonical
242    order: Latte, Frappé, Macchiato, Mocha.
243
244    Flavors can also be looked up by identifier, such as `PALETTE["mocha"]` or
245    `PALETTE[FlavorName.MOCHA]`.
246    """
247
248    latte: Flavor
249    """The light flavor."""
250    frappe: Flavor
251    """The lightest dark flavor."""
252    macchiato: Flavor
253    """The medium dark flavor."""
254    mocha: Flavor
255    """The darkest dark flavor."""
256
257    def __iter__(self) -> Iterator[Flavor]:
258        """Iterate over flavors in the palette."""
259        yield from [self.latte, self.frappe, self.macchiato, self.mocha]
260
261    def __getitem__(self, name: str) -> Flavor:
262        """Look up a flavor by identifier, such as `"mocha"` or `FlavorName.MOCHA`.
263
264        Raises `KeyError` if there is no flavor with that identifier.
265        """
266        try:
267            identifier = FlavorName(name)
268        except ValueError:
269            raise KeyError(name) from None
270        return cast(Flavor, getattr(self, identifier))
@dataclass(frozen=True)
class Palette:
237@dataclass(frozen=True)
238class Palette:
239    """The top-level type that encompasses the Catppuccin palette data structure.
240
241    Primarily used via the `PALETTE` constant.
242    Can be iterated over, in which case the flavors are yielded in the canonical
243    order: Latte, Frappé, Macchiato, Mocha.
244
245    Flavors can also be looked up by identifier, such as `PALETTE["mocha"]` or
246    `PALETTE[FlavorName.MOCHA]`.
247    """
248
249    latte: Flavor
250    """The light flavor."""
251    frappe: Flavor
252    """The lightest dark flavor."""
253    macchiato: Flavor
254    """The medium dark flavor."""
255    mocha: Flavor
256    """The darkest dark flavor."""
257
258    def __iter__(self) -> Iterator[Flavor]:
259        """Iterate over flavors in the palette."""
260        yield from [self.latte, self.frappe, self.macchiato, self.mocha]
261
262    def __getitem__(self, name: str) -> Flavor:
263        """Look up a flavor by identifier, such as `"mocha"` or `FlavorName.MOCHA`.
264
265        Raises `KeyError` if there is no flavor with that identifier.
266        """
267        try:
268            identifier = FlavorName(name)
269        except ValueError:
270            raise KeyError(name) from None
271        return cast(Flavor, getattr(self, identifier))

The top-level type that encompasses the Catppuccin palette data structure.

Primarily used via the PALETTE constant. Can be iterated over, in which case the flavors are yielded in the canonical order: Latte, Frappé, Macchiato, Mocha.

Flavors can also be looked up by identifier, such as PALETTE["mocha"] or PALETTE[FlavorName.MOCHA].

latte: Flavor

The light flavor.

frappe: Flavor

The lightest dark flavor.

macchiato: Flavor

The medium dark flavor.

mocha: Flavor

The darkest dark flavor.

@dataclass(frozen=True)
class Flavor:
216@dataclass(frozen=True)
217class Flavor:
218    """A flavor is a collection of colors.
219
220    Catppuccin has four flavors; Latte, Frappé, Macchiato, and Mocha.
221    """
222
223    name: str
224    """A human-readable name such as `Latte` or `Mocha`."""
225    identifier: str
226    """The lowercase key used to identify the flavor. This differs from `name`
227    in that it's intended for machine usage rather than presentation"""
228    order: int
229    """Order of the flavor in the palette spec."""
230    dark: bool
231    """Whether this flavor is dark or light oriented. Latte is light, the other
232    three flavors are dark."""
233    colors: FlavorColors
234    """@public"""

A flavor is a collection of colors.

Catppuccin has four flavors; Latte, Frappé, Macchiato, and Mocha.

name: str

A human-readable name such as Latte or Mocha.

identifier: str

The lowercase key used to identify the flavor. This differs from name in that it's intended for machine usage rather than presentation

order: int

Order of the flavor in the palette spec.

dark: bool

Whether this flavor is dark or light oriented. Latte is light, the other three flavors are dark.

colors: FlavorColors

@dataclass(frozen=True)
class FlavorColors:
110@dataclass(frozen=True)
111class FlavorColors:
112    """All of the colors for a particular flavor of Catppuccin.
113
114    Can be iterated over, in which case the colors are yielded in order.
115
116    Colors can also be looked up by identifier, such as `colors["red"]` or
117    `colors[ColorName.RED]`.
118    """
119
120    rosewater: Color
121    """@public"""
122    flamingo: Color
123    """@public"""
124    pink: Color
125    """@public"""
126    mauve: Color
127    """@public"""
128    red: Color
129    """@public"""
130    maroon: Color
131    """@public"""
132    peach: Color
133    """@public"""
134    yellow: Color
135    """@public"""
136    green: Color
137    """@public"""
138    teal: Color
139    """@public"""
140    sky: Color
141    """@public"""
142    sapphire: Color
143    """@public"""
144    blue: Color
145    """@public"""
146    lavender: Color
147    """@public"""
148    text: Color
149    """@public"""
150    subtext1: Color
151    """@public"""
152    subtext0: Color
153    """@public"""
154    overlay2: Color
155    """@public"""
156    overlay1: Color
157    """@public"""
158    overlay0: Color
159    """@public"""
160    surface2: Color
161    """@public"""
162    surface1: Color
163    """@public"""
164    surface0: Color
165    """@public"""
166    base: Color
167    """@public"""
168    mantle: Color
169    """@public"""
170    crust: Color
171    """@public"""
172
173    def __iter__(self) -> Iterator[Color]:
174        """Iterate over colors in the flavor."""
175        yield from [
176            self.rosewater,
177            self.flamingo,
178            self.pink,
179            self.mauve,
180            self.red,
181            self.maroon,
182            self.peach,
183            self.yellow,
184            self.green,
185            self.teal,
186            self.sky,
187            self.sapphire,
188            self.blue,
189            self.lavender,
190            self.text,
191            self.subtext1,
192            self.subtext0,
193            self.overlay2,
194            self.overlay1,
195            self.overlay0,
196            self.surface2,
197            self.surface1,
198            self.surface0,
199            self.base,
200            self.mantle,
201            self.crust,
202        ]
203
204    def __getitem__(self, name: str) -> Color:
205        """Look up a color by identifier, such as `"red"` or `ColorName.RED`.
206
207        Raises `KeyError` if there is no color with that identifier.
208        """
209        try:
210            identifier = ColorName(name)
211        except ValueError:
212            raise KeyError(name) from None
213        return cast(Color, getattr(self, identifier))

All of the colors for a particular flavor of Catppuccin.

Can be iterated over, in which case the colors are yielded in order.

Colors can also be looked up by identifier, such as colors["red"] or colors[ColorName.RED].

rosewater: Color

flamingo: Color

pink: Color

mauve: Color

red: Color

maroon: Color

peach: Color

yellow: Color

green: Color

teal: Color

sky: Color

sapphire: Color

blue: Color

lavender: Color

text: Color

subtext1: Color

subtext0: Color

overlay2: Color

overlay1: Color

overlay0: Color

surface2: Color

surface1: Color

surface0: Color

base: Color

mantle: Color

crust: Color

@dataclass(frozen=True)
class Color:
 85@dataclass(frozen=True)
 86class Color:
 87    """A single color in the Catppuccin palette."""
 88
 89    name: str
 90    """A human-readable name such as `Pink` or `Surface0`."""
 91    identifier: str
 92    """The lowercase key used to identify the color. This differs from `name` in
 93    that it's intended for machine usage rather than presentation."""
 94    accent: bool
 95    """Whether the color is considered an accent color. Accent colors are the
 96    first 14 colors in the palette, also called the analogous colours. The
 97    remaining 12 non-accent colors are also referred to as the monochromatic
 98    colors."""
 99    order: int
100    """Order of the color in the palette spec."""
101    hex: str
102    """The color represented as a six-digit hex string with a leading hash (#)."""
103    rgb: RGB
104    """The color represented as individual red, green, and blue channels. (0-255)"""
105    hsl: HSL
106    """The color represented as individual hue (0-359), saturation (0-1), and
107    lightness (0-1) channels."""

A single color in the Catppuccin palette.

name: str

A human-readable name such as Pink or Surface0.

identifier: str

The lowercase key used to identify the color. This differs from name in that it's intended for machine usage rather than presentation.

accent: bool

Whether the color is considered an accent color. Accent colors are the first 14 colors in the palette, also called the analogous colours. The remaining 12 non-accent colors are also referred to as the monochromatic colors.

order: int

Order of the color in the palette spec.

hex: str

The color represented as a six-digit hex string with a leading hash (#).

rgb: RGB

The color represented as individual red, green, and blue channels. (0-255)

hsl: HSL

The color represented as individual hue (0-359), saturation (0-1), and lightness (0-1) channels.

@dataclass(frozen=True)
class RGB:
61@dataclass(frozen=True)
62class RGB:
63    """Color represented as red, green, and blue (all 0-255)."""
64
65    r: int
66    """@public"""
67    g: int
68    """@public"""
69    b: int
70    """@public"""

Color represented as red, green, and blue (all 0-255).

r: int

g: int

b: int

@dataclass(frozen=True)
class HSL:
73@dataclass(frozen=True)
74class HSL:
75    """Color represented as hue (0-359), saturation (0-1), and lightness (0-1)."""
76
77    h: float
78    """@public"""
79    s: float
80    """@public"""
81    l: float  # noqa: E741
82    """@public"""

Color represented as hue (0-359), saturation (0-1), and lightness (0-1).

h: float

s: float

l: float

class FlavorName(enum.StrEnum):
21class FlavorName(StrEnum):
22    """Identifiers of the flavors, in palette order."""
23
24    LATTE = "latte"
25    FRAPPE = "frappe"
26    MACCHIATO = "macchiato"
27    MOCHA = "mocha"

Identifiers of the flavors, in palette order.

class ColorName(enum.StrEnum):
30class ColorName(StrEnum):
31    """Identifiers of the colors in a flavor, in palette order."""
32
33    ROSEWATER = "rosewater"
34    FLAMINGO = "flamingo"
35    PINK = "pink"
36    MAUVE = "mauve"
37    RED = "red"
38    MAROON = "maroon"
39    PEACH = "peach"
40    YELLOW = "yellow"
41    GREEN = "green"
42    TEAL = "teal"
43    SKY = "sky"
44    SAPPHIRE = "sapphire"
45    BLUE = "blue"
46    LAVENDER = "lavender"
47    TEXT = "text"
48    SUBTEXT1 = "subtext1"
49    SUBTEXT0 = "subtext0"
50    OVERLAY2 = "overlay2"
51    OVERLAY1 = "overlay1"
52    OVERLAY0 = "overlay0"
53    SURFACE2 = "surface2"
54    SURFACE1 = "surface1"
55    SURFACE0 = "surface0"
56    BASE = "base"
57    MANTLE = "mantle"
58    CRUST = "crust"

Identifiers of the colors in a flavor, in palette order.