{"id":7098,"library":"colorhash","title":"ColorHash","description":"ColorHash is a lightweight Python library for generating deterministic colors from any object. By calculating a color value based on an object's hash, it ensures consistent results: the same input will always yield the same color. It is currently at version 2.3.0 and has an active development cycle, with recent updates focusing on performance and wider Python version compatibility.","status":"active","version":"2.3.0","language":"en","source_language":"en","source_url":"https://github.com/dimostenis/color-hash-python","tags":["color","hash","utility","frontend","ui","deterministic"],"install":[{"cmd":"pip install colorhash","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"ColorHash","correct":"from colorhash import ColorHash"}],"quickstart":{"code":"from colorhash import ColorHash\n\n# Generate a color for a string\nc = ColorHash('Hello World')\n\n# Access color representations\nprint(f\"HSL: {c.hsl}\")   # (Hue, Saturation, Lightness)\nprint(f\"RGB: {c.rgb}\")   # (Red, Green, Blue)\nprint(f\"Hex: {c.hex}\")   # Hexadecimal color string\n\n# Customize color generation (e.g., specific lightness range)\nc_custom = ColorHash('Another Object', lightness=[0.2, 0.4, 0.6])\nprint(f\"Custom Hex: {c_custom.hex}\")","lang":"python","description":"Initialize ColorHash with any object (typically a string) and retrieve its deterministic color in HSL, RGB, or hexadecimal format. You can also customize the lightness, saturation, or hue ranges during initialization to influence the generated colors."},"warnings":[{"fix":"Review the documentation for `ColorHash` constructor parameters (`lightness`, `saturation`, `min_h`, `max_h`) and ensure your inputs conform to the expected types and ranges.","message":"Version 2.0.0 introduced exposure of parameters to influence colors (lightness, saturation, hue ranges) and runtime validation of input parameters. Code relying on implicit color generation or passing non-standard values might encounter new validation errors or altered color outputs.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your Python environment to version 3.8 or newer to ensure full compatibility and support.","message":"As of version 2.1.0, Python 3.7 is no longer officially tested. While it 'shall work', future compatibility or undetected bugs might arise for users on Python 3.7. The library officially supports Python 3.8+.","severity":"deprecated","affected_versions":">=2.1.0"},{"fix":"To maximize color variety for distinct inputs, use a wider range of values for `lightness` and `saturation` sequences (e.g., `[0.3, 0.5, 0.7]`) and/or broader `min_h`/`max_h` hue ranges.","message":"Setting very narrow or identical ranges for `lightness`, `saturation`, or `hue` during `ColorHash` initialization can result in multiple different input objects generating colors that are almost indistinguishable.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Expand the sequences of `lightness` and `saturation` values (e.g., `lightness=[0.2, 0.4, 0.6, 0.8]`), or widen the `min_h`/`max_h` hue range to allow `ColorHash` more options to deterministically select a distinct color.","cause":"The default or custom `lightness`, `saturation`, or `hue` ranges provided to the `ColorHash` constructor are too restrictive, limiting the available color spectrum for differentiation.","error":"Colors generated for different inputs are too similar."},{"fix":"Use the correct attributes to retrieve the desired color format: `c.hex` for hexadecimal string, `c.rgb` for an RGB tuple, or `c.hsl` for an HSL tuple.","cause":"Attempting to access color information using an incorrect or non-existent attribute name on the `ColorHash` object. The library provides specific attributes for color representations.","error":"AttributeError: 'ColorHash' object has no attribute 'color' (or similar for other missing attributes)."}]}