philiprehberger-color-convert
Convert between color formats: hex, RGB, HSL, HSV, CMYK, and named CSS colors.
Installation
pip install philiprehberger-color-convert
Usage
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
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
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
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
# Each method returns a new Color — chain freely
warm = Color("#3498db").desaturate(20).lighten(10)
print(warm.hex)
Palette Generation
c = Color("#ff6b35")
c.analogous() # [Color, Color, Color]
c.triadic() # [Color, Color, Color]
c.split_complementary() # [Color, Color, Color]
Contrast Ratio
white = Color("#ffffff")
black = Color("#000000")
white.contrast_ratio(black) # 21.0
Mixing Colors
red = Color("#ff0000")
blue = Color("#0000ff")
red.mix(blue) # 50/50 mix → Color('#800080')
red.mix(blue, weight=0.25) # 25% blue → closer to red
red.mix(blue, weight=0.75) # 75% blue → closer to blue
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) |
.mix(other, weight=0.5) |
Blend with another Color in RGB space |
css_color_names() |
Sorted list of all 148 supported CSS color names |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-color-convert 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_color_convert-0.2.0.tar.gz | 9.8 kB | Without provenance | Details for philiprehberger_color_convert-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_color_convert-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_color_convert-0.2.0-py3-none-any.whl |
Total release size: 17.9 kB
Release files / philiprehberger_color_convert-0.2.0.tar.gz
| Download URL | philiprehberger_color_convert-0.2.0.tar.gz |
|---|---|
| Size | 9.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4617888092293e9bd8a1a53c15cda104c8e84242235135e216a6b0de94cd5216
|
|
BLAKE2b-256 checksum How to use checksums |
5efc8475b484b55233d487c75cb1ef3e06cfd9f0812f3288d6ac259ecb2b466b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_color_convert-0.2.0-py3-none-any.whl
| Download URL | philiprehberger_color_convert-0.2.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
15b897aa68b145e39d480c6354c8c5501f4b71cafcb25d37d6999274910c46b5
|
|
BLAKE2b-256 checksum How to use checksums |
c12417e491859271d5928bcdf03b500532e1445e8abe5b2a346b2bad6d1c7e54
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-color-convert 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.