colorhash
Generate color based on any object
What it is and what it does
ColorHash is a lightweight Python library that maps any input object to a deterministic color by computing a hash and converting it to HSL, RGB, or hex format. The same input always produces the same color output, making it useful for UI elements like user avatars or category labels where visual consistency matters. The library supports Python 3.8 through 3.15 and has zero runtime dependencies, keeping it simple to integrate.
You control the output by adjusting hue range (min_h to max_h), saturation levels, and lightness levels. The library picks deterministically from the ranges you provide, so you can create narrow color palettes or wide variety depending on your needs. The core API is straightforward: instantiate ColorHash with an object and optional parameters, then access the .hsl, .rgb, or .hex properties.
Use it for:
- Assign consistent avatar colors to users based on their identifier across a web application.
- Generate category or tag colors that remain stable even after data reloads or cache refreshes.
- Create color-coded visual indicators for status or priority levels in dashboards.
- Build theme-aware color schemes by constraining hue ranges to match brand guidelines.
- Implement deterministic syntax highlighting or data visualization where the same entity always gets the same color.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Generates deterministic colors from any object by hashing its value, returning results in HSL, RGB, and hex formats with customizable hue, saturation, and lightness ranges.
Yes. Zero dependencies, active maintenance, no known vulnerabilities, and a permissive MIT license make this a low-risk addition. Install it if you need deterministic color mapping for UI consistency; the API is minimal and the library does one thing well.
Install
colorhash on PyPI
pip
pip install colorhashuv
uv add colorhashpoetry
poetry add colorhashInstalling colorhash
Before you install
Low install friction with no runtime dependencies. Actively maintained as of 2026-03-12 with recent fixes to hue calculation and support for modern Python versions.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed-source projects with minimal attribution requirements.
Quickstart
pip install colorhash
from colorhash import ColorHash
c = ColorHash('Hello World')
print(c.hex) # '#2dd24b'
print(c.rgb) # (45, 210, 75)
print(c.hsl) # (131, 0.65, 0.5)
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<3.16,>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 155 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 384,160/month — #7,069 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: colorhash-2.3.0-py3-none-any.whl
Keywords: color, hash, hex, hsl, rgb
Tags
More Graphics packages
Pillow adds image processing capabilities to…
permissive · top 100 on PyPI
fonttoolsfonttools manipulates font files in multiple…
permissive · top 1,000 on PyPI
matplotlib-inlineEnables matplotlib figures to display inline…
permissive · top 1,000 on PyPI
pymupdfPyMuPDF extracts, renders, converts, and…
agpl · top 1,000 on PyPI
pypdfium2pypdfium2 is a Python binding to PDFium that…
permissive · top 1,000 on PyPI
altairAltair is a declarative Python library for…
permissive · top 1,000 on PyPI
colourConverts between and manipulates color…
permissive · top 5,000 on PyPI
colourmapGenerates unique RGB and HEX colors from input…
permissive · top 15,000 on PyPI
ImageHashImageHash computes perceptual fingerprints of…
permissive · top 5,000 on PyPI
colorzerocolorzero provides a simple, immutable color…
permissive · top 15,000 on PyPI
materialyoucolorGenerates Material Design 3 color schemes and…
unclear · top 15,000 on PyPI
webcolorsConverts and normalizes HTML and CSS color…
permissive · top 1,000 on PyPI
coloraideColorAide is a pure Python library for…
permissive · top 15,000 on PyPI
colorloverProvides a library of human-friendly color…
unclear · top 15,000 on PyPI
hashringImplements consistent hashing in Python using…
permissive · top 15,000 on PyPI