# qualpal.Qualpal

Python · 1.1.0

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

<a id="constructor"></a>

```python
Qualpal(
    colors: Sequence[str] | None = None,
    colorspace: dict[str, tuple[float, float]] | None = None,
    palette: str | None = None,
    space: str = "hsl",
    cvd: dict[str, float] | None = None,
    metric: str = "ciede2000",
    background: str | None = None,
    max_memory: float = 1.0,
    colorspace_size: int = 1000
)
```

Generate qualitative color palettes with distinct colors.

The Qualpal class provides a stateful builder for generating color
palettes. You can specify colors, colorspace, or palette as input,
and configure parameters like CVD simulation, distance metric, etc.

<a id="__init__"></a>

## `__init__`

```python
__init__(
    colors: Sequence[str] | None = None,
    colorspace: dict[str, tuple[float, float]] | None = None,
    palette: str | None = None,
    space: str = "hsl",
    cvd: dict[str, float] | None = None,
    metric: str = "ciede2000",
    background: str | None = None,
    max_memory: float = 1.0,
    colorspace_size: int = 1000
) -> None
```

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

Initialize Qualpal object.

### Parameters

**colors** : *Sequence\[str\] \| None*

List of hex color strings to use as starting point.
Mutually exclusive with colorspace and palette.

**colorspace** : *dict\[str, tuple\[float, float\]\] \| None*

Colorspace specification with ranges for each dimension.
Keys depend on ‘space’ parameter:
- ‘hsl’: ‘h’, ‘s’, ‘l’
- ‘lchab’: ‘h’, ‘c’, ‘l’
Each value is a (min, max) tuple.
Mutually exclusive with colors and palette.

**palette** : *str \| None*

Named palette in format ‘source:name’ (e.g., ‘ColorBrewer:Set1’).
Mutually exclusive with colors and colorspace.

**space** : *str*

Color space to use: ‘hsl’ (default) or ‘lchab’.

**cvd** : *dict\[str, float\] \| None*

Color vision deficiency simulation. Keys: ‘protan’, ‘deutan’, ‘tritan’.
Values: 0.0 (normal) to 1.0 (complete deficiency).

**metric** : *str*

Color difference metric: ‘ciede2000’ (default), ‘din99d’, or ‘cie76’.

**background** : *str \| None*

Background color as hex string (e.g., ‘\#ffffff’).

**max\_memory** : *float*

Maximum memory to use in GB (default: 1.0).

**colorspace\_size** : *int*

Number of colors to sample from colorspace (default: 1000).

### Raises

`ValueError`

If multiple of colors/colorspace/palette are provided,
    or if any parameter has invalid values.

`TypeError`

If parameter types are incorrect.

<a id="cvd"></a>

## `cvd`

```python
cvd(self) -> dict[str, float] | None
```

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

Get color vision deficiency simulation settings.

<a id="metric"></a>

## `metric`

```python
metric(self) -> str
```

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

Get color difference metric.

<a id="background"></a>

## `background`

```python
background(self) -> str | None
```

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

Get background color.

<a id="max_memory"></a>

## `max_memory`

```python
max_memory(self) -> float
```

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

Get maximum memory in GB.

<a id="colorspace_size"></a>

## `colorspace_size`

```python
colorspace_size(self) -> int
```

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

Get colorspace size.

<a id="generate"></a>

## `generate`

```python
generate(n: int) -> qualpal.Palette
```

[Source](<https://github.com/jolars/qualpal-py/blob/72a59d3a05195fb48e82e53ededa466950ed7d67/qualpal/qualpal.py>)

Generate a color palette with n distinct colors.

### Parameters

**n** : *int*

Number of colors to generate.

### Returns

*Palette*

A Palette object containing n Color objects.

### Raises

`RuntimeError`

If palette generation fails (e.g., C++ algorithm error).

`ValueError`

If n is not positive.

`TypeError`

If n is not an integer.

### Notes

Behavior depends on input mode:

- **colorspace mode**: Samples n colors from the continuous color space
- **colors mode**: Selects n most distinct colors from the provided list
- **palette mode**: Loads named palette and selects n most distinct colors
