Metadata-Version: 2.4
Name: philiprehberger-color-convert
Version: 0.1.9
Summary: Convert between color formats: hex, RGB, HSL, HSV, CMYK, and named CSS colors
Project-URL: Homepage, https://github.com/philiprehberger/py-color-convert#readme
Project-URL: Repository, https://github.com/philiprehberger/py-color-convert
Project-URL: Issues, https://github.com/philiprehberger/py-color-convert/issues
Project-URL: Changelog, https://github.com/philiprehberger/py-color-convert/blob/main/CHANGELOG.md
Author: Philip Rehberger
License-Expression: MIT
License-File: LICENSE
Keywords: color,convert,hex,hsl,rgb
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# philiprehberger-color-convert

[![Tests](https://github.com/philiprehberger/py-color-convert/actions/workflows/publish.yml/badge.svg)](https://github.com/philiprehberger/py-color-convert/actions/workflows/publish.yml)
[![PyPI version](https://img.shields.io/pypi/v/philiprehberger-color-convert.svg)](https://pypi.org/project/philiprehberger-color-convert/)
[![Last updated](https://img.shields.io/github/last-commit/philiprehberger/py-color-convert)](https://github.com/philiprehberger/py-color-convert/commits/main)

Convert between color formats: hex, RGB, HSL, HSV, CMYK, and named CSS colors.

## Installation

```bash
pip install philiprehberger-color-convert
```

## Usage

```python
from philiprehberger_color_convert import Color

# Create from hex
c = Color("#ff6b35")

# Create from CSS named color
c = Color("tomato")

# Create from RGB string
c = Color("rgb(255, 107, 53)")

# Create from another Color
c2 = Color(c)
```

### Factory Methods

```python
c = Color.from_rgb(255, 107, 53)
c = Color.from_hsl(20, 100, 60)
c = Color.from_hsv(20, 79, 100)
c = Color.from_cmyk(0, 58, 79, 0)
```

### Format Properties

```python
c = Color("#ff6b35")

c.rgb   # (255, 107, 53)
c.hex   # "#ff6b35"
c.hsl   # (16, 100, 60)
c.hsv   # (16, 79, 100)
c.cmyk  # (0, 58, 79, 0)
```

### Manipulation

```python
c = Color("#ff6b35")

lighter = c.lighten(20)
darker = c.darken(20)
more = c.saturate(10)
less = c.desaturate(10)
comp = c.complement()
inv = c.invert()
```

### Chaining

```python
# Each method returns a new Color — chain freely
warm = Color("#3498db").desaturate(20).lighten(10)
print(warm.hex)
```

### Palette Generation

```python
c = Color("#ff6b35")

c.analogous()            # [Color, Color, Color]
c.triadic()              # [Color, Color, Color]
c.split_complementary()  # [Color, Color, Color]
```

### Contrast Ratio

```python
white = Color("#ffffff")
black = Color("#000000")

white.contrast_ratio(black)  # 21.0
```

## API

| Method / Property | Description |
|-------------------|-------------|
| `Color(value)` | Create from hex, RGB string, CSS name, or Color |
| `Color.from_rgb(r, g, b)` | Create from RGB values (0-255) |
| `Color.from_hsl(h, s, l)` | Create from HSL (h: 0-360, s/l: 0-100) |
| `Color.from_hsv(h, s, v)` | Create from HSV (h: 0-360, s/v: 0-100) |
| `Color.from_cmyk(c, m, y, k)` | Create from CMYK (0-100 each) |
| `.rgb` | RGB tuple `(r, g, b)` |
| `.hex` | Hex string `"#rrggbb"` |
| `.hsl` | HSL tuple `(h, s, l)` |
| `.hsv` | HSV tuple `(h, s, v)` |
| `.cmyk` | CMYK tuple `(c, m, y, k)` |
| `.lighten(percent)` | Return lighter Color |
| `.darken(percent)` | Return darker Color |
| `.saturate(percent)` | Return more saturated Color |
| `.desaturate(percent)` | Return less saturated Color |
| `.complement()` | Return complementary Color |
| `.invert()` | Return inverted Color |
| `.analogous()` | List of 3 analogous Colors |
| `.triadic()` | List of 3 triadic Colors |
| `.split_complementary()` | List of 3 split-complementary Colors |
| `.contrast_ratio(other)` | WCAG contrast ratio (float) |
| `css_color_names()` | Sorted list of all 148 supported CSS color names |

## Development

```bash
pip install -e .
python -m pytest tests/ -v
```

## Support

If you find this project useful:

⭐ [Star the repo](https://github.com/philiprehberger/py-color-convert)

🐛 [Report issues](https://github.com/philiprehberger/py-color-convert/issues?q=is%3Aissue+is%3Aopen+label%3Abug)

💡 [Suggest features](https://github.com/philiprehberger/py-color-convert/issues?q=is%3Aissue+is%3Aopen+label%3Aenhancement)

❤️ [Sponsor development](https://github.com/sponsors/philiprehberger)

🌐 [All Open Source Projects](https://philiprehberger.com/open-source-packages)

💻 [GitHub Profile](https://github.com/philiprehberger)

🔗 [LinkedIn Profile](https://www.linkedin.com/in/philiprehberger)

## License

[MIT](LICENSE)
