Skip to main content

Introduction

duckfn_palette is a DuckDB loadable extension that wraps three Rust color crates as SQL functions: palette for 44 color spaces, conversion, blending, color difference and contrast, schemes, white points, CAM16 and 8-bit packing; csscolorparser for CSS Color Level 4 strings; and colorous for the d3-scale-chromatic gradients and categorical palettes. Together they register 160 functions under the plt_ prefix, and once the extension is loaded they behave like DuckDB's own. You do not need to know how it was written or to compile anything — the CLI, a Python or R session and the browser build all take the same .duckdb_extension file.

A color is one STRUCT, so it can live in a column, be passed around as a value, and be compared:

STRUCT(space VARCHAR, c1 DOUBLE, c2 DOUBLE, c3 DOUBLE, alpha DOUBLE)

Install it​

INSTALL duckfn_palette FROM community;
LOAD duckfn_palette;

Then call the functions in any query:

SELECT plt_to_hex(plt_convert(plt_srgb(1, 0.5, 0), 'oklch')) AS as_oklch,
plt_difference(plt_named('red'), plt_named('blue'), 'ciede2000') AS delta_e;

That block runs right here, in your browser: the site preloads the extension from the project's latest release, so there is no LOAD to write. Installation covers the other ways to get the file.

Where to go next​

  • Installation — the community repository, a release file, or a local build.
  • Functions — every function, grouped by what it does, with examples you can run.
  • Development guide — building the extension from source. That part is for people working on this repository; it is not needed to use the extension.