On this page

API reference

How autodoc output is drawn: signatures on a raised strip, then their description, parameters and return values.

A small module documented on the API page, to show how autodoc output is drawn.

Nothing here is part of the theme.

class palette.Mode(*values)[source]

Bases: Enum

Whether a theme is for light or dark surroundings.

LIGHT = 'light'

A light background with dark text.

DARK = 'dark'

A dark background with light text.

class palette.Colour(lightness: float, chroma: float, hue: float)[source]

Bases: object

A colour in the OKLCH space.

Parameters:
  • lightness – Perceived lightness, from 0 to 1.

  • chroma – How colourful it is, from 0 upwards.

  • hue – The hue angle in degrees.

lightness: float
chroma: float
hue: float
css() → str[source]

Return the colour as a CSS oklch() value.

>>> Colour(0.55, 0.2, 280).css()
'oklch(55.0% 0.2 280)'
class palette.Palette(name: str, mode: Mode = Mode.LIGHT, colours: dict[str, ~palette.Colour]=<factory>)[source]

Bases: object

A named set of colours, as one daisyUI theme defines them.

Parameters:
  • name – The theme’s name, as used in data-theme.

  • mode – Whether the theme is light or dark.

  • colours – Colours by token name, such as "primary".

Example

>>> palette = Palette("brand", Mode.LIGHT)
>>> palette.add("primary", Colour(0.55, 0.2, 280))
name: str
mode: Mode = 'light'
colours: dict[str, Colour]
add(token: str, colour: Colour) → None[source]

Set the colour for one token.

Parameters:
  • token – The token’s name without the --color- prefix.

  • colour – The colour to use.

Raises:

ValueError – If the token’s name is empty.

to_css() → str[source]

Return the palette as a CSS rule for its data-theme selector.

Returns:

One rule, setting a --color-* variable for each token.

property is_dark: bool

Whether the palette is for dark mode.

palette.contrast_ratio(foreground: Colour, background: Colour, *, large_text: bool = False) → float[source]

Estimate the contrast between two colours from their lightness.

A rough estimate for checking a palette, not a WCAG measurement.

Parameters:
  • foreground – The text colour.

  • background – The colour behind the text.

  • large_text – Whether the text is large, which needs less contrast.

Returns:

A ratio from 1 to 21.

palette.DEFAULT_THEMES: tuple[str, ...] = ('light', 'dark')

The themes the picker offers when none are named.

Hand-written entries

palette.build(source: str, *, theme: str = 'light') → None

Build the documentation at source with theme.

Parameters:
  • source – The directory that holds conf.py.

  • theme – The daisyUI theme to start with.

Raises:

FileNotFoundError – If source has no conf.py.

--theme <name>

The daisyUI theme to build with.

DAISY_LAYOUT

Builds this site with another layout code.

theme_picker
Type:
bool or list[str]
Default:
False

The themes offered to the reader.