gradpyent module

Generate color gradients from RGB, HTML, and KML color inputs.

class gradpyent.Gradient(gradient_start: RGB | list[int] | tuple[int, int, int] | str | None = None, gradient_end: RGB | list[int] | tuple[int, int, int] | str | None = None, opacity: float | None = 1.0)[source]

Bases: object

Represents a color gradient between two points.

generate(steps: int) → list[RGB][source]

Generate a list of evenly spaced colors along the gradient.

Parameters:

steps (int) – How many colors to generate (>=2).

Returns:

List of RGB objects from start to end color.

Return type:

List[RGB]

Raises:

ValueError – If steps < 2.

get_color_at(t: float) → RGB[source]

Interpolate color at position t along the gradient.

Parameters:

t (float) – Position between start and end, in [0.0, 1.0].

Returns:

Interpolated color at position t.

Return type:

RGB

Raises:

ValueError – If t is not within [0.0, 1.0].

get_gradient_series(series: Iterable[Any], fmt: str = 'rgb', opacity: float | None = None) → list[RGB | tuple[int, int, int] | str][source]

Generate a gradient mapped to the values in a numeric series.

Parameters:
  • series (Iterable) – Numeric iterable (ints or floats).

  • fmt (str) – Output color format: “rgb” (default), “html”, or “kml”.

  • opacity (float, optional) – Opacity for KML, overrides constructor value if set.

Returns:

List of colors in the requested format, one for each series value.

Return type:

List

Raises:

ValueError – If the series is empty or contains non-numeric values.

class gradpyent.RGB(red: int, green: int, blue: int)[source]

Bases: object

Represents a color in RGB format.

property blue: int

Blue component value.

Type:

int

property green: int

Green component value.

Type:

int

property red: int

Red component value.

Type:

int

gradpyent.get_verified_color(arg: str | RGB | Sequence[int]) → RGB[source]
gradpyent.get_verified_color(arg: str) → RGB
gradpyent.get_verified_color(arg: RGB) → RGB
gradpyent.get_verified_color(arg: Sequence) → RGB

Convert an input value to an RGB instance.

Supported input types are:
  • str: named color, “rgb(r,g,b)” string, HTML hex (“#RRGGBB”), or KML hex (“AABBGGRR”)

  • RGB: color instance (returned as-is)

  • sequence of three integers: RGB tuple or list

Parameters:

arg (Any) – Color value to convert.

Returns:

The equivalent RGB color.

Return type:

RGB

Raises:

ValueError – If the input type or value is unrecognized.

gradpyent.known_colors() → dict[str, RGB][source]

Return a dictionary mapping known color names to RGB values.

Covers the 16 basic HTML/CSS color names (not the full 147-name extended/X11 palette).

Returns:

Mapping of color name (lowercase) to corresponding RGB object.

Return type:

Dict[str, RGB]