Skip to main content

🐍 Soothing pastel theme for Python.

Project description

Logo
Catppuccin for Python

Installation

Install with pip or your preferred dependency management tool.

pip install catppuccin

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

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 = getattr(flavor.colors, field.name)
    print(f"{field.name}: {color.hex}")

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

Pygments Styles

This package provides a Pygments style for each of the four Catppuccin flavors.

Install Catppuccin with the pygments feature to include the relevant dependencies:

pip install catppuccin[pygments]

The styles are registered as importlib entrypoints, which allows Pygments to find them by name:

from pygments.styles import get_style_by_name

get_style_by_name("catppuccin-frappe")
# catppuccin.extras.pygments.FrappeStyle

The following style names are available:

  • catppuccin-latte
  • catppuccin-frappe
  • catppuccin-macchiato
  • catppuccin-mocha

They can also be accessed by directly importing them:

from catppuccin.extras.pygments import MacchiatoStyle

IPython

A minimal configuration:

c.TerminalInteractiveShell.true_color = True
c.TerminalInteractiveShell.highlighting_style = "catppuccin-mocha"

Putting this into your IPython configuration and ensuring catppuccin[pygments] is installed in the same environment will give you Catppuccin Mocha syntax highlighting in the REPL. See here for an example of a more complete configuration.

Matplotlib

The library tries to register styles and colormaps if matplotlib is installed. See the examples below for some use cases:

  1. Load a style, using mpl.style.use
    import catppuccin
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    mpl.style.use(catppuccin.PALETTE.mocha.identifier)
    plt.plot([0,1,2,3], [1,2,3,4])
    plt.show()
    
  2. Mix it with different stylesheets!
    import catppuccin
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    
    mpl.style.use(["ggplot", catppuccin.PALETTE.mocha.identifier])
    plt.plot([0,1,2,3], [1,2,3,4])
    plt.show()
    
  3. Load individual colors
    import matplotlib.pyplot as plt
    import catppuccin
    from catppuccin.extras.matplotlib import load_color
    
    color = load_color(catppuccin.PALETTE.latte.identifier, "peach")
    plt.plot([0,1,2,3], [1,2,3,4], color=color)
    plt.show()
    
  4. Define custom colormaps
    import matplotlib.pyplot as plt
    import numpy as np
    import catppuccin
    from catppuccin.extras.matplotlib import get_colormap_from_list
    
    cmap = get_colormap_from_list(
        catppuccin.PALETTE.frappe.identifier,
        ["red", "peach", "yellow", "green"],
    )
    rng = np.random.default_rng()
    data = rng.integers(2, size=(30, 30))
    
    plt.imshow(data, cmap=cmap)
    plt.show()
    

Contribution

If you are looking to contribute, please read through our CONTRIBUTING.md first!

Development

This project is maintained with Poetry. If you don't have Poetry yet, you can install it using the installation instructions.

Install the project's dependencies including extras:

poetry install --all-extras

Codegen

catppuccin/palette.py is generated by a build script based on the contents of palette.json.

To update after downloading a new palette JSON file:

poetry run python build.py

Formatting this file is done manually as with any other file, see Code Standards below.

Code Standards

Before committing changes, it is recommended to run the following tools to ensure consistency in the codebase.

ruff format
ruff check
mypy .
pytest --cov catppuccin

These tools are all installed as part of the dev dependency group with Poetry. You can use poetry shell to automatically put these tools in your path.

💝 Thanks to

 

Copyright © 2022-present Catppuccin Org

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

catppuccin-2.3.3.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

catppuccin-2.3.3-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file catppuccin-2.3.3.tar.gz.

File metadata

  • Download URL: catppuccin-2.3.3.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for catppuccin-2.3.3.tar.gz
Algorithm Hash digest
SHA256 9a8f82ffc58a8dd70bcffe55e39cbe9a212dc9fd7be716201759040af043b6fa
MD5 bad179f858c9c01a3dacfe3b3ba7a239
BLAKE2b-256 3bb378baf82fafdb2570ec372ef11032dda429cc933c19728b14bb546c793e71

See more details on using hashes here.

File details

Details for the file catppuccin-2.3.3-py3-none-any.whl.

File metadata

  • Download URL: catppuccin-2.3.3-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/6.5.0-1025-azure

File hashes

Hashes for catppuccin-2.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a41454dfcfa3632cb85ade4580e8dc2d70e7f666cea58ec354b0a3ca3d5e2f8c
MD5 82651e1eb1f15447e6640ac913d92d9f
BLAKE2b-256 15f213a187f24a1f715c36db4403b3f694eaf9fa2367d8137a5ed87ba696b76f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page