Registry / serialization / colorhash

colorhash

JSON →
library2.3.0pypypi✓ verified 87d ago

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.

pip install colorhash
INSTALL
IMPORT
SIG · COLORHASH
C
colorhash
serializationpythonv2.3.0
Install
1.5s avg
Import
107ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.114s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.099s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ColorHash
from colorhash import ColorHash

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.

from colorhash import ColorHash # Generate a color for a string c = ColorHash('Hello World') # Access color representations print(f"HSL: {c.hsl}") # (Hue, Saturation, Lightness) print(f"RGB: {c.rgb}") # (Red, Green, Blue) print(f"Hex: {c.hex}") # Hexadecimal color string # Customize color generation (e.g., specific lightness range) c_custom = ColorHash('Another Object', lightness=[0.2, 0.4, 0.6]) print(f"Custom Hex: {c_custom.hex}")
Debug
Known issues
breakingVersion 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.
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.
affects: >=2.0.0
deprecatedAs 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+.
fix
Upgrade your Python environment to version 3.8 or newer to ensure full compatibility and support.
affects: >=2.1.0
gotchaSetting 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.
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.
affects: All
Errors
Common errors & fixes
Colors generated for different inputs are too similar.
The default or custom `lightness`, `saturation`, or `hue` ranges provided to the `ColorHash` constructor are too restrictive, limiting the available color spectrum for differentiation.
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.
AttributeError: 'ColorHash' object has no attribute 'color' (or similar for other missing attributes).
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.
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.
Upgrade
Version history
2.3.0latest on PyPI · released Mar 12, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
colorhash — pip install colorhash · libregistry