tintelligence-color-utils


Nametintelligence-color-utils JSON
Version 0.1.11 PyPI version JSON
download
home_pageNone
SummaryUtility functions for working with colors (conversion, manipulation, validation).
upload_time2025-11-01 17:22:15
maintainerNone
docs_urlNone
authortintelligence
requires_python>=3.9
licenseMIT License Copyright (c) 2025 tintelligence Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords color color-conversion colors hsl lab lch rgb
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # tintelligence-color-utils

Utility functions for working with colors: conversions, manipulations, family assignment, sorting, and optional Qt helpers.

## Installation

```bash
pip install tintelligence-color-utils
```

### Optional Qt support
If you need `QColor` helpers, install with one of the extras:

- PySide6:
  ```bash
  pip install "tintelligence-color-utils[qt_pyside6]"
  ```
- PyQt6:
  ```bash
  pip install "tintelligence-color-utils[qt_pyqt6]"
  ```

## Quick start

```python
from tintelligence_color_utils import hex_to_hsv, get_color_family
# or
from color_utils import hex_to_hsv, get_color_family

h, s, v = hex_to_hsv("#FF7F00")
print(h, s, v)
print(get_color_family(h, s, v))
```

## API Reference
All functions are available from `color_utils` or `tintelligence_color_utils` top-level import.

### Conversion

#### HEX to RGB

```python
hex_to_rgb(hex_code: str) -> tuple[float, float, float]
```

Convert `#RRGGBB` or `RRGGBB` to an `(r, g, b)` tuple in `[0, 1]`. Raises `ValueError` on invalid input.

#### HEX to HSV

```python
hex_to_hsv(hex_code: str) -> tuple[float, float, float]
```

Convert a hex color to HSV `(h, s, v)` where `h ∈ [0,1]`.

#### Integer RGB to HEX

```python
rgb_to_hex(r: int, g: int, b: int) -> str
```

Convert integer RGB (0-255) to `#RRGGBB`.

#### HEX midpoint

```python
hex_midpoint(c1: str | None, c2: str | None) -> str | None
```

Midpoint between two hex colors as `#RRGGBB`. Returns `None` if inputs are invalid.

#### RGB to LAB

```python
rgb_to_lab(r: int, g: int, b: int) -> tuple[float, float, float]
```

Approximate sRGB (D65) to CIE L*a*b* with `L ∈ [0..100]`.

#### Normalize LAB

```python
normalize_lab(l: float | None, a: float | None, b: float | None) -> tuple[float | None, float | None, float | None]
```

Normalize Lab to `[0,1]` each. `L/100`, and `a,b` via `(v+128)/255` when needed.

#### RGB to HSL

```python
rgb_to_hsl(r: int, g: int, b: int) -> tuple[int, int, int]
```

Convert RGB (0-255) to HSL where `H ∈ [0..360]`, `S,L ∈ [0..100]` (ints).

#### LAB to LCH

```python
lab_to_lch(l: float, a: float, b: float) -> tuple[float, float, float]
```

Convert CIE Lab to LCH(ab) `(L, C, H_deg)`.

#### Get Brigtness from HEX
```python
brightness_from_hex(hex_color: str) -> float | None
```

Perceived brightness (Lab L) from a hex color. Higher means brighter.

### Color families

#### Get color family

```python
get_color_family(hue: float, saturation: float, value: float) -> str
```

Assign a color family based on HSV, with handling for dark and muted tones. Families include e.g. "Black", "Grey", "White / Off-white", "Red", "Pink", "Orange", "Yellow", "Green", "Turquoise / Teal", "Blue", "Purple / Violet", "Brown", "Unknown".

### Shades

#### Get darker shades

```python
get_darker_shades(hex_code: str, steps: int = 2, factor: float = 0.8) -> tuple[str, ...]
```

Generate `steps` darker hex shades by multiplying V by `factor` iteratively.

### Sorting

#### Sort paints by color

```python
sort_paints_by_color(paints: list[dict], mode: str = "hue") -> list[dict]
```

Sort a list of paint dicts by `"hue"`, `"saturation"`, or `"value"`. Expects `hsv_h`, `hsv_s`, `hsv_v` fields.

#### Group paints by color family and sort by hue

```python
sort_paints_by_family_value_hue(
    paints: list[dict],
    order: Literal["bright_to_dark", "dark_to_bright"] = "bright_to_dark",
    color_families: list[dict] | None = None,
) -> list[dict]
```

Group by `color_family_id` (using the provided `color_families` order if given; otherwise numeric id order), then sort by HSV V in the chosen order, tie-breaking by HSV H. Returns items enriched with `_hsv` and `_family` when `color_families` is provided.

#### Group paints by color family and sort by LAB brightness

```python
sort_paints_by_family_lab_brightness(
    paints: list[dict],
    order: Literal["bright_to_dark", "dark_to_bright"] = "bright_to_dark",
    color_families: list[dict] | None = None,
) -> list[dict]
```

Group by `color_family_id` (using the provided `color_families` order if given; otherwise numeric id order), then sort by Lab L in the chosen order, tie-breaking by `hsv_h` if present.

#### Sort HEX colors by brightness

```python
sort_hex_by_brightness(hex_codes: list[str], order: Literal["bright_to_dark", "dark_to_bright"] = "bright_to_dark") -> list[str]
```

Sort a list of hex color codes by perceived brightness (Lab L). Invalid hex codes are placed at the end.

### Qt helper (optional)

#### HEX to QColor

```python
color_utils.qcolor.to_qcolor(color) -> QColor
```

Convert a hex string, `(r, g, b)` tuple, or `QColor` instance to a `QColor`. Requires PySide6, PyQt6, or a `qt_core.QColor` shim. Raises `RuntimeError` if no `QColor` is available.

## Development

- Python 3.9+
- Install dev deps: `pip install -e .[dev]`
- Build: `python -m build`
- Test: `pytest`

## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "tintelligence-color-utils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "color, color-conversion, colors, hsl, lab, lch, rgb",
    "author": "tintelligence",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/52/23/4091c9c9d6ed52e2ad176d6116b516124f6af2f29885564df089cd075bbc/tintelligence_color_utils-0.1.11.tar.gz",
    "platform": null,
    "description": "# tintelligence-color-utils\n\nUtility functions for working with colors: conversions, manipulations, family assignment, sorting, and optional Qt helpers.\n\n## Installation\n\n```bash\npip install tintelligence-color-utils\n```\n\n### Optional Qt support\nIf you need `QColor` helpers, install with one of the extras:\n\n- PySide6:\n  ```bash\n  pip install \"tintelligence-color-utils[qt_pyside6]\"\n  ```\n- PyQt6:\n  ```bash\n  pip install \"tintelligence-color-utils[qt_pyqt6]\"\n  ```\n\n## Quick start\n\n```python\nfrom tintelligence_color_utils import hex_to_hsv, get_color_family\n# or\nfrom color_utils import hex_to_hsv, get_color_family\n\nh, s, v = hex_to_hsv(\"#FF7F00\")\nprint(h, s, v)\nprint(get_color_family(h, s, v))\n```\n\n## API Reference\nAll functions are available from `color_utils` or `tintelligence_color_utils` top-level import.\n\n### Conversion\n\n#### HEX to RGB\n\n```python\nhex_to_rgb(hex_code: str) -> tuple[float, float, float]\n```\n\nConvert `#RRGGBB` or `RRGGBB` to an `(r, g, b)` tuple in `[0, 1]`. Raises `ValueError` on invalid input.\n\n#### HEX to HSV\n\n```python\nhex_to_hsv(hex_code: str) -> tuple[float, float, float]\n```\n\nConvert a hex color to HSV `(h, s, v)` where `h \u2208 [0,1]`.\n\n#### Integer RGB to HEX\n\n```python\nrgb_to_hex(r: int, g: int, b: int) -> str\n```\n\nConvert integer RGB (0-255) to `#RRGGBB`.\n\n#### HEX midpoint\n\n```python\nhex_midpoint(c1: str | None, c2: str | None) -> str | None\n```\n\nMidpoint between two hex colors as `#RRGGBB`. Returns `None` if inputs are invalid.\n\n#### RGB to LAB\n\n```python\nrgb_to_lab(r: int, g: int, b: int) -> tuple[float, float, float]\n```\n\nApproximate sRGB (D65) to CIE L*a*b* with `L \u2208 [0..100]`.\n\n#### Normalize LAB\n\n```python\nnormalize_lab(l: float | None, a: float | None, b: float | None) -> tuple[float | None, float | None, float | None]\n```\n\nNormalize Lab to `[0,1]` each. `L/100`, and `a,b` via `(v+128)/255` when needed.\n\n#### RGB to HSL\n\n```python\nrgb_to_hsl(r: int, g: int, b: int) -> tuple[int, int, int]\n```\n\nConvert RGB (0-255) to HSL where `H \u2208 [0..360]`, `S,L \u2208 [0..100]` (ints).\n\n#### LAB to LCH\n\n```python\nlab_to_lch(l: float, a: float, b: float) -> tuple[float, float, float]\n```\n\nConvert CIE Lab to LCH(ab) `(L, C, H_deg)`.\n\n#### Get Brigtness from HEX\n```python\nbrightness_from_hex(hex_color: str) -> float | None\n```\n\nPerceived brightness (Lab L) from a hex color. Higher means brighter.\n\n### Color families\n\n#### Get color family\n\n```python\nget_color_family(hue: float, saturation: float, value: float) -> str\n```\n\nAssign a color family based on HSV, with handling for dark and muted tones. Families include e.g. \"Black\", \"Grey\", \"White / Off-white\", \"Red\", \"Pink\", \"Orange\", \"Yellow\", \"Green\", \"Turquoise / Teal\", \"Blue\", \"Purple / Violet\", \"Brown\", \"Unknown\".\n\n### Shades\n\n#### Get darker shades\n\n```python\nget_darker_shades(hex_code: str, steps: int = 2, factor: float = 0.8) -> tuple[str, ...]\n```\n\nGenerate `steps` darker hex shades by multiplying V by `factor` iteratively.\n\n### Sorting\n\n#### Sort paints by color\n\n```python\nsort_paints_by_color(paints: list[dict], mode: str = \"hue\") -> list[dict]\n```\n\nSort a list of paint dicts by `\"hue\"`, `\"saturation\"`, or `\"value\"`. Expects `hsv_h`, `hsv_s`, `hsv_v` fields.\n\n#### Group paints by color family and sort by hue\n\n```python\nsort_paints_by_family_value_hue(\n    paints: list[dict],\n    order: Literal[\"bright_to_dark\", \"dark_to_bright\"] = \"bright_to_dark\",\n    color_families: list[dict] | None = None,\n) -> list[dict]\n```\n\nGroup by `color_family_id` (using the provided `color_families` order if given; otherwise numeric id order), then sort by HSV V in the chosen order, tie-breaking by HSV H. Returns items enriched with `_hsv` and `_family` when `color_families` is provided.\n\n#### Group paints by color family and sort by LAB brightness\n\n```python\nsort_paints_by_family_lab_brightness(\n    paints: list[dict],\n    order: Literal[\"bright_to_dark\", \"dark_to_bright\"] = \"bright_to_dark\",\n    color_families: list[dict] | None = None,\n) -> list[dict]\n```\n\nGroup by `color_family_id` (using the provided `color_families` order if given; otherwise numeric id order), then sort by Lab L in the chosen order, tie-breaking by `hsv_h` if present.\n\n#### Sort HEX colors by brightness\n\n```python\nsort_hex_by_brightness(hex_codes: list[str], order: Literal[\"bright_to_dark\", \"dark_to_bright\"] = \"bright_to_dark\") -> list[str]\n```\n\nSort a list of hex color codes by perceived brightness (Lab L). Invalid hex codes are placed at the end.\n\n### Qt helper (optional)\n\n#### HEX to QColor\n\n```python\ncolor_utils.qcolor.to_qcolor(color) -> QColor\n```\n\nConvert a hex string, `(r, g, b)` tuple, or `QColor` instance to a `QColor`. Requires PySide6, PyQt6, or a `qt_core.QColor` shim. Raises `RuntimeError` if no `QColor` is available.\n\n## Development\n\n- Python 3.9+\n- Install dev deps: `pip install -e .[dev]`\n- Build: `python -m build`\n- Test: `pytest`\n\n## License\n\nMIT\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 tintelligence\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "Utility functions for working with colors (conversion, manipulation, validation).",
    "version": "0.1.11",
    "project_urls": {
        "Homepage": "https://github.com/Tintelligence-App/color-utils",
        "Issues": "https://github.com/Tintelligence-App/color-utils/issues",
        "Repository": "https://github.com/Tintelligence-App/color-utils"
    },
    "split_keywords": [
        "color",
        " color-conversion",
        " colors",
        " hsl",
        " lab",
        " lch",
        " rgb"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a827b2e0279feb2f77c7c55c6514a62f0692fb841d0947c2c6b01bd6e1dd0482",
                "md5": "9d3fa57e1d565552b46b615a8fab684e",
                "sha256": "fee13764514d5e791e6c27ac5c80a3b7ebdc4dfd429131081509655cf1f18a5b"
            },
            "downloads": -1,
            "filename": "tintelligence_color_utils-0.1.11-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d3fa57e1d565552b46b615a8fab684e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 12508,
            "upload_time": "2025-11-01T17:22:14",
            "upload_time_iso_8601": "2025-11-01T17:22:14.052718Z",
            "url": "https://files.pythonhosted.org/packages/a8/27/b2e0279feb2f77c7c55c6514a62f0692fb841d0947c2c6b01bd6e1dd0482/tintelligence_color_utils-0.1.11-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "52234091c9c9d6ed52e2ad176d6116b516124f6af2f29885564df089cd075bbc",
                "md5": "6c48aee0750d0aaf7b33f898b06cbf21",
                "sha256": "653be37d0e9397c50494d6f45df402fb3f99de605b96a5180a98e81ed71dc495"
            },
            "downloads": -1,
            "filename": "tintelligence_color_utils-0.1.11.tar.gz",
            "has_sig": false,
            "md5_digest": "6c48aee0750d0aaf7b33f898b06cbf21",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 8844,
            "upload_time": "2025-11-01T17:22:15",
            "upload_time_iso_8601": "2025-11-01T17:22:15.046753Z",
            "url": "https://files.pythonhosted.org/packages/52/23/4091c9c9d6ed52e2ad176d6116b516124f6af2f29885564df089cd075bbc/tintelligence_color_utils-0.1.11.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-11-01 17:22:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Tintelligence-App",
    "github_project": "color-utils",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "tintelligence-color-utils"
}
        
Elapsed time: 1.23050s