Registry / serialization / hsluv
library5.0.4pypypi✓ verified 92d ago

HSLuv is a Python implementation of a human-friendly HSL (Hue, Saturation, Lightness) color space, which is an alternative to standard HSL. It's built upon CIELUV, a perceptually uniform color space, extending it with a saturation component that allows spanning all available chroma as a percentage. The library, currently at version 5.0.4, provides functions for converting between HSLuv, HPLuv (pastel variant), RGB, and hexadecimal color representations. It maintains an active development status with periodic updates.

pip install hsluv
INSTALL
IMPORT
SIG · HSLUV
H
hsluv
serializationpythonv5.0.4
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v5.0.4 · 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.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

hsluv_to_hex
✓ from hsluv import hsluv_to_hex
hex_to_hsluv
✓ from hsluv import hex_to_hsluv
rgb_to_hsluv
✓ from hsluv import rgb_to_hsluv
hsluv_to_rgb
✓ from hsluv import hsluv_to_rgb
hpluv_to_hex
✓ from hsluv import hpluv_to_hex
hex_to_hpluv
✓ from hsluv import hex_to_hpluv

This quickstart demonstrates how to use the core conversion functions of the `hsluv` library to transform colors between HSLuv, hexadecimal, and RGB formats. HSLuv takes hue (0-360), saturation (0-100), and lightness (0-100). RGB input/output values are floats between 0 and 1.

from hsluv import hsluv_to_hex, hex_to_hsluv, rgb_to_hsluv, hsluv_to_rgb # Convert HSLuv to Hex hsluv_color = [240.0, 100.0, 50.0] # Blue color (Hue, Saturation, Lightness) hex_code = hsluv_to_hex(hsluv_color) print(f"HSLuv {hsluv_color} -> Hex: {hex_code}") # Convert Hex to HSLuv parsed_hsluv = hex_to_hsluv("#0000FF") # Pure Blue print(f"Hex #0000FF -> HSLuv: {parsed_hsluv}") # Convert RGB to HSLuv (RGB values 0-1) rgb_color = [0.0, 0.0, 1.0] # Pure Blue converted_hsluv = rgb_to_hsluv(rgb_color) print(f"RGB {rgb_color} -> HSLuv: {converted_hsluv}") # Convert HSLuv to RGB (RGB values 0-1) hsluv_to_rgb_example = [240.0, 100.0, 50.0] # Blue converted_rgb = hsluv_to_rgb(hsluv_to_rgb_example) print(f"HSLuv {hsluv_to_rgb_example} -> RGB: {converted_rgb}")
Debug
Known issues
breakingVersion 5.x and later require Python 3.7 or newer. Python 2 users must install `hsluv==5.0.0` or earlier versions for compatibility.
fix
Upgrade to Python 3.7+ or pin `hsluv` to a version compatible with Python 2 (e.g., `pip install hsluv==5.0.0`).
affects: >=5.0.0
gotchaThe library does not 'clamp' floating point errors, meaning output values for color components might be slightly outside their expected ranges (e.g., RGB values slightly less than 0 or greater than 1, or HSLuv components slightly out of range).
fix
For display or strict validation, consider rounding the output values to a desired precision or clamping them to their expected ranges after conversion.
affects: All versions
gotchaEnsure input types match function expectations. For example, `hsluv_to_rgb` expects hue (0-360), saturation (0-100), and lightness (0-100) as floats. `rgb_to_hsluv` expects R, G, B as floats between 0 and 1. Mis-matched types could lead to unexpected results or `TypeError`s.
fix
Always refer to the function signatures and documentation to provide inputs in the correct format and range.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'hsluv'
The 'hsluv' library is not installed in the current Python environment or the Python interpreter cannot locate it.
fix
pip install hsluv
TypeError: hsluv_to_rgb() takes 1 positional argument but 3 were given
The `hsluv_to_rgb` and similar conversion functions expect a single iterable (list or tuple) containing three float values for color components (e.g., hue, saturation, lightness), but received separate arguments.
fix
Ensure you pass a single list or tuple as the argument, for example: `hsluv_to_rgb([hue, saturation, lightness])`.
hsluv rgb returns negative values
The `hsluv` library, by design, does not clamp floating-point errors, which can result in RGB components (and other color space values) being slightly outside their expected ranges (e.g., RGB values slightly less than 0 or greater than 1).
fix
Manually clamp or round the output values to their expected ranges after conversion. For example, for RGB components: `rgb_clamped = [max(0.0, min(1.0, c)) for c in rgb_raw]`.
Upgrade
Version history
5.0.4latest on PyPI · released Sep 11, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
Resources
hsluv — pip install hsluv · libregistry