Install catppuccin
mainInstall the catppuccin package using pip or your preferred Python dependency management tool.
pip install catppuccinrepository·main·Indexed 41 days ago
https://github.com/catppuccin/pythonA soothing pastel theme for Python (v2.5.0) providing color palettes and syntax highlighting for IPython and Pygments. It includes a structured palette hierarchy (Palette, Flavor, FlavorColors, and Color) with support for RGB and HSL representations, and optional integrations for matplotlib, pygments, and rich.
Install the catppuccin package using pip or your preferred Python dependency management tool.
pip install catppuccinTo use Catppuccin syntax highlighting in the IPython REPL, you must ensure catppuccin[pygments] is installed in your environment. Then, add the following configuration to your IPython configuration file (e.g., ipython_config.py).
Available IPython themes:
catppuccin-lattecatppuccin-frappecatppuccin-macchiatocatppuccin-mochac.TerminalInteractiveShell.true_color = True
c.TerminalInteractiveShell.highlighting_style = "catppuccin-mocha"Catppuccin provides optional support for the following libraries:
The Catppuccin data structure is organized into a hierarchy:
Palette: The top-level container. It contains the four flavors: latte (light), frappe (lightest dark), macchiato (medium dark), and mocha (darkest dark). Iterating over a Palette yields flavors in this order.Flavor: Represents one of the four themes. It includes metadata like name, identifier, order, and dark (boolean), and holds a colors object.FlavorColors: A collection of 26 Color objects specific to that flavor.from catppuccin.models import Palette
# Accessing specific flavors
latte_colors = palette.latte.colors
mocha_base = palette.mocha.colors.base
# Iterating through the hierarchy
for flavor in palette:
print(f"Flavor: {flavor.name} (Dark: {flavor.dark})")
for color in flavor.colors:
print(f" - {color.name}: {color.hex}")The Palette and FlavorColors objects are iterable. You can iterate over the PALETTE to get all available flavors, or iterate over a specific flavor's .colors attribute to access its individual color objects.
from catppuccin import PALETTE
# Iterate through flavors
for flavor in PALETTE:
print(flavor.name)
# Iterate through colors in a specific flavor
for color in PALETTE.latte.colors:
print(f"{color.name}: {color.hex}")The PALETTE object is the central entry point for accessing all Catppuccin color schemes (flavors) and their constituent colors. It contains predefined flavors such as latte, frappe, macchiato, and mocha. Each flavor contains a collection of Color objects identified by names like rosewater, flamingo, pink, mauve, red, etc.
Each Color object provides multiple representations of the color, including:
hex: The hexadecimal string representation.rgb: An RGB object with r, g, and b components.hsl: An HSL object with h, s, and l components.identifier: The unique string ID for the color.accent: A boolean indicating if the color is an accent color.from catppuccin.palette import PALETTE
# Example: Accessing a specific color from the Mocha flavor
mocha_red_hex = PALETTE.mocha.colors.red.hex
print(mocha_red_hex) # Output: #f38ba8
# Example: Accessing RGB values
mocha_red_rgb = PALETTE.mocha.colors.red.rgb
print(mocha_red_rgb.r, mocha_red_rgb.g, mocha_red_rgb.b)The Catppuccin palette is structured as a collection of Color objects organized by flavor (e.g., Mocha, Macchiato, Frappé, Latte). Each color is identified by a specific name and identifier. Common identifiers include:
surface2, surface1, surface0 (used for UI layering).base, mantle, crust (used for different levels of background depth).Each Color object provides the color value in multiple formats: hex, rgb (as an RGB object), and hsl (as an HSL object).
# Example of accessing color properties (conceptual based on structure)
color = palette.mocha.base
print(color.hex) # '#1e1e2e'
print(color.rgb.r) # 30
print(color.hsl.h) # 240.0Since Palette, Flavor, and Color are implemented as Python dataclasses, you can use the standard dataclasses.fields utility to programmatically inspect and iterate through color names and their properties.
from dataclasses import fields
from catppuccin import PALETTE
flavor = PALETTE.frappe
for field in fields(flavor.colors):
color = getattr(flavor.colors, field.name)
print(f"{field.name}: {color.hex}")You can access the complete color palette via the PALETTE constant. The palette is organized into flavors (Latte, Frappé, Macchiato, Mocha), and each flavor contains a collection of colors. Colors can be accessed using their names and provide both .hex and .rgb properties.
from catppuccin import PALETTE
# Accessing hex codes
hex_val = PALETTE.latte.colors.mauve.hex
# '#8839ef'
# Accessing RGB values
rgb_val = PALETTE.mocha.colors.teal.rgb
# RGB(r=148, g=226, b=213)The RGB and HSL dataclasses provide structured ways to access color channel data.
RGB: Contains r, g, and b integers (0-255).HSL: Contains h (hue, 0-359), s (saturation, 0-1), and l (lightness, 0-1) floats.from catppuccin.models import RGB, HSL
rgb_color = RGB(r=255, g=128, b=0)
hsl_color = HSL(h=30.0, s=1.0, l=0.5)The FlavorColors class contains all 26 specific color definitions for a Catppuccin flavor (e.g., rosewater, mauve, base, crust).
You can access colors directly by their attribute names or iterate over the FlavorColors instance to yield all colors in their canonical order.
from catppuccin.models import FlavorColors
# Assuming 'colors' is an instance of FlavorColors
print(colors.mauve.hex)
print(colors.base.hex)
# Iterating over all colors in order
for color in colors:
print(f"{color.name}: {color.hex}")The Color class represents a single color in the Catppuccin palette and provides multiple formats for the same color value:
name: Human-readable name (e.g., Pink).identifier: Machine-readable lowercase key.accent: Boolean indicating if it is an accent color (the first 14 colors).order: The color's position in the palette spec.hex: Six-digit hex string with a leading #.rgb: An RGB instance.hsl: An HSL instance.