catppuccin

🐍 Soothing pastel theme for Python.

Basic Usage

Get access to the palette with the catppuccin.PALETTE constant:

from catppuccin import PALETTE

PALETTE.latte.colors.mauve.hex
# '#8839ef'
PALETTE.mocha.colors.teal.rgb
# RGB(r=148, g=226, b=213)

The Palette data structure matches the palette JSON.

Iteration

Both Palette and FlavorColors can be iterated to yield flavors and colors respectively:

for flavor in PALETTE:
    print(flavor.name)

# Latte
# Frappé
# Macchiato
# Mocha

for color in PALETTE.latte.colors:
    print(f"{color.name}: {color.hex}")

# Rosewater: #f2d5cf
# Flamingo: #eebebe
# Pink: #f4b8e4
# ...
# Base: #303446
# Mantle: #292c3c
# Crust: #232634

Lookup by name

Flavors and colors can also be looked up via the FlavorName and ColorName enums:

from catppuccin import PALETTE, ColorName, FlavorName

PALETTE[FlavorName.MOCHA].colors[ColorName.RED].hex
# '#f38ba8'
PALETTE["latte"].colors["mauve"].hex
# '#8839ef'

def accent(flavor: FlavorName, color: ColorName) -> str:
    return PALETTE[flavor].colors[color].hex

Dataclasses

Palette, Flavor, Color et cetera are all dataclasses, so you can also inspect and iterate their fields using methods from the dataclass module.

For example, to list all color names and their hex codes:

from dataclasses import fields
from catppuccin import PALETTE

flavor = PALETTE.frappe
for field in fields(flavor.colors):
    color = flavor.colors[field.name]
    print(f"{field.name}: {color.hex}")

# rosewater: #f2d5cf
# flamingo: #eebebe
# pink: #f4b8e4
# ...
# base: #303446
# mantle: #292c3c
# crust: #232634

Types

This package is fully type annotated with data structures located in the models module.

Integrations

This package includes optional support for several libraries. Click a link below to see the documentation for that integration.

  1"""🐍 Soothing pastel theme for Python.
  2
  3## Basic Usage
  4
  5Get access to the palette with the `catppuccin.PALETTE` constant:
  6
  7```python
  8from catppuccin import PALETTE
  9
 10PALETTE.latte.colors.mauve.hex
 11# '#8839ef'
 12PALETTE.mocha.colors.teal.rgb
 13# RGB(r=148, g=226, b=213)
 14```
 15
 16The `Palette` data structure matches [the palette
 17JSON](https://github.com/catppuccin/palette/blob/main/palette.json).
 18
 19## Iteration
 20
 21Both `Palette` and `FlavorColors` can be iterated to yield flavors and colors
 22respectively:
 23
 24```python
 25for flavor in PALETTE:
 26    print(flavor.name)
 27
 28# Latte
 29# Frappé
 30# Macchiato
 31# Mocha
 32
 33for color in PALETTE.latte.colors:
 34    print(f"{color.name}: {color.hex}")
 35
 36# Rosewater: #f2d5cf
 37# Flamingo: #eebebe
 38# Pink: #f4b8e4
 39# ...
 40# Base: #303446
 41# Mantle: #292c3c
 42# Crust: #232634
 43```
 44
 45## Lookup by name
 46
 47Flavors and colors can also be looked up via the `FlavorName` and `ColorName`
 48enums:
 49
 50```python
 51from catppuccin import PALETTE, ColorName, FlavorName
 52
 53PALETTE[FlavorName.MOCHA].colors[ColorName.RED].hex
 54# '#f38ba8'
 55PALETTE["latte"].colors["mauve"].hex
 56# '#8839ef'
 57
 58def accent(flavor: FlavorName, color: ColorName) -> str:
 59    return PALETTE[flavor].colors[color].hex
 60```
 61
 62## Dataclasses
 63
 64`Palette`, `Flavor`, `Color` et cetera are all
 65[`dataclasses`](https://docs.python.org/3/library/dataclasses.html),
 66so you can also inspect and iterate their fields using methods from the
 67dataclass module.
 68
 69For example, to list all color names and their hex codes:
 70
 71```python
 72from dataclasses import fields
 73from catppuccin import PALETTE
 74
 75flavor = PALETTE.frappe
 76for field in fields(flavor.colors):
 77    color = flavor.colors[field.name]
 78    print(f"{field.name}: {color.hex}")
 79
 80# rosewater: #f2d5cf
 81# flamingo: #eebebe
 82# pink: #f4b8e4
 83# ...
 84# base: #303446
 85# mantle: #292c3c
 86# crust: #232634
 87```
 88
 89## Types
 90
 91This package is fully type annotated with data structures located in [the models
 92module](./catppuccin/models.html).
 93
 94## Integrations
 95
 96This package includes optional support for several libraries. Click a link below
 97to see the documentation for that integration.
 98
 99- [matplotlib](./catppuccin/extras/matplotlib.html)
100- [pygments](./catppuccin/extras/pygments.html)
101- [rich](./catppuccin/extras/rich_ctp.html)
102
103"""
104
105import importlib.util
106
107from catppuccin.models import ColorName as ColorName
108from catppuccin.models import FlavorName as FlavorName
109from catppuccin.palette import PALETTE as PALETTE
110
111# Register colormaps if matplotlib is available
112if importlib.util.find_spec("matplotlib") is not None:
113    import catppuccin.extras.matplotlib  # noqa: F401