Pure Python color engine — hex to RGB/HSL/CMYK/OKLCH conversion, WCAG contrast checker, color harmonies, Tailwind shades, and color blindness simulation. Zero dependencies.
Project description
colorfyi
Pure Python color engine for developers. Convert between 7 color spaces (hex, RGB, HSL, HSV, CMYK, CIE Lab, OKLCH), check WCAG contrast ratios, generate color harmonies and Tailwind-style shades, simulate color blindness, and create smooth gradients — all with zero dependencies and sub-millisecond performance.
Extracted from ColorFYI, a color reference platform with 809 named colors across 6 color systems (CSS, X11, Crayola, Pantone, RAL, NCS), 544 brand color palettes, and interactive tools used by developers and designers worldwide.
Try the interactive tools at colorfyi.com — color converter, contrast checker, palette generator, shade generator, color blindness simulator, and gradient generator.
Table of Contents
- Install
- Quick Start
- What You Can Do
- Command-Line Interface
- MCP Server (Claude, Cursor, Windsurf)
- REST API Client
- API Reference
- Learn More About Color
- Also Available
- FYIPedia Developer Tools
- License
Install
pip install colorfyi # Core engine (zero deps)
pip install "colorfyi[cli]" # + Command-line interface (typer, rich)
pip install "colorfyi[mcp]" # + MCP server for AI assistants
pip install "colorfyi[api]" # + HTTP client for colorfyi.com API
pip install "colorfyi[all]" # Everything
Or run instantly without installing:
uvx --from colorfyi colorfyi info FF6B35
Quick Start
from colorfyi import get_color_info, contrast_ratio, harmonies, generate_shades
# Convert any hex color to 7 color spaces instantly
info = get_color_info("FF6B35")
print(info.rgb) # RGB(r=255, g=107, b=53)
print(info.hsl) # HSL(h=16.0, s=100.0, l=60.4)
print(info.cmyk) # CMYK(c=0.0, m=58.0, y=79.2, k=0.0)
print(info.oklch) # OKLCH(l=0.685, c=0.179, h=42.9)
# WCAG 2.1 contrast ratio with AA/AAA compliance checks
cr = contrast_ratio("FF6B35", "FFFFFF")
print(cr.ratio) # 3.38
print(cr.aa_large) # True
print(cr.aaa_normal) # False
# Generate all 5 harmony types at once
h = harmonies("FF6B35")
print(h.complementary) # ['35C0FF']
print(h.analogous) # ['FF3535', 'FFA135']
print(h.triadic) # ['6B35FF', '35FF6B']
# Tailwind-style shade palette (50-950)
shades = generate_shades("3498DB")
for shade in shades:
print(f"{shade.level}: #{shade.hex}")
What You Can Do
Color Space Conversion
Convert between 7 color spaces in a single call. Each space has different strengths:
| Color Space | Best For | Example |
|---|---|---|
| Hex | Web/CSS, shorthand notation | #FF6B35 |
| RGB | Screen display, digital design | rgb(255, 107, 53) |
| HSL | Intuitive hue/saturation/lightness adjustments | hsl(16°, 100%, 60%) |
| HSV | Color pickers (Photoshop, Figma) | hsv(16°, 79%, 100%) |
| CMYK | Print design, physical media | cmyk(0%, 58%, 79%, 0%) |
| CIE Lab | Perceptually uniform comparisons, Delta E | Lab(65.4, 42.1, 47.8) |
| OKLCH | Modern CSS (oklch()), perceptual palettes |
oklch(0.685, 0.179, 42.9) |
from colorfyi import get_color_info
info = get_color_info("3B82F6") # Tailwind Blue 500
print(info.rgb) # RGB(r=59, g=130, b=246)
print(info.hsl) # HSL(h=217.2, s=91.2, l=59.8)
print(info.oklch) # OKLCH(l=0.623, c=0.184, h=259.1)
Learn more: Color Converter Tool · What is OKLCH? · Color Space Guide
WCAG Contrast Checking
Test color pairs against WCAG 2.1 accessibility guidelines. The Web Content Accessibility Guidelines require a minimum contrast ratio of 4.5:1 for normal text (AA) and 7:1 for enhanced contrast (AAA).
from colorfyi import contrast_ratio, text_color_for_bg
# Check if your color combination is accessible
cr = contrast_ratio("1E40AF", "FFFFFF") # Dark blue on white
print(cr.ratio) # 8.55
print(cr.aa_normal) # True (≥ 4.5:1)
print(cr.aa_large) # True (≥ 3:1)
print(cr.aaa_normal) # True (≥ 7:1)
print(cr.aaa_large) # True (≥ 4.5:1)
# Automatically pick black or white text for any background
text = text_color_for_bg("FF6B35") # → "000000" (black text)
text = text_color_for_bg("1E3A5F") # → "FFFFFF" (white text)
Learn more: WCAG Contrast Checker · Contrast Ratio Guide
Color Harmonies
Generate aesthetically pleasing color combinations based on color wheel theory. Five harmony types cover different design needs:
| Harmony | Description | Use Case |
|---|---|---|
| Complementary | Opposite on the color wheel | High contrast, bold designs |
| Analogous | Adjacent colors (±30°) | Cohesive, harmonious palettes |
| Triadic | Three evenly spaced (120°) | Vibrant, balanced layouts |
| Split-complementary | Complement + neighbors | Softer contrast than complementary |
| Tetradic | Four colors (rectangle) | Rich, complex color schemes |
from colorfyi import harmonies
h = harmonies("FF6B35")
print(h.complementary) # ['35C0FF']
print(h.analogous) # ['FF3535', 'FFA135']
print(h.triadic) # ['6B35FF', '35FF6B']
print(h.split_complementary) # ['3565FF', '35FFA1']
print(h.tetradic) # ['C035FF', '35FF6B', '35C0FF']
Learn more: Palette Generator · Color Harmony Guide
Tailwind-Style Shades
Generate a full 50–950 shade scale from any base color, matching Tailwind CSS conventions. Essential for building design systems and consistent UI themes.
from colorfyi import generate_shades
shades = generate_shades("3B82F6") # Generate shades from Tailwind Blue 500
# shade.level: 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950
for shade in shades:
print(f"{shade.level}: #{shade.hex}")
Learn more: Shade Generator · Tailwind CSS Colors
Color Blindness Simulation
Approximately 8% of men and 0.5% of women have some form of color vision deficiency (CVD). Simulate how your colors appear to users with different types of color blindness using Viénot transformation matrices.
from colorfyi import simulate_color_blindness
cb = simulate_color_blindness("FF6B35")
print(cb.protanopia) # Red-blind (~1% of men)
print(cb.deuteranopia) # Green-blind (~6% of men, most common)
print(cb.tritanopia) # Blue-blind (rare, ~0.01%)
print(cb.achromatopsia) # Total color blindness (monochromacy)
Learn more: Color Blindness Simulator · Color Vision Deficiency Guide
Perceptual Color Comparison
Compare colors using CIE76 Delta E — a metric designed to match human perception. Unlike simple RGB distance, Delta E accounts for how our eyes actually perceive color differences.
| Delta E | Perception |
|---|---|
| 0–1 | Not perceptible |
| 1–2 | Barely perceptible |
| 2–10 | Perceptible at close look |
| 10–50 | Clearly different |
| 50+ | Very different |
from colorfyi import compare_colors, mix_colors, gradient_steps
# CIE76 Delta E perceptual distance
cmp = compare_colors("FF6B35", "3498DB")
print(cmp.delta_e) # 42.3
print(cmp.delta_e_category) # "Very Different"
# Mix colors in Lab space (perceptually uniform)
mixed = mix_colors("FF0000", "0000FF", ratio=0.5)
# Smooth gradient with perceptual interpolation
colors = gradient_steps("FF6B35", "3498DB", steps=7)
Learn more: Gradient Generator · Delta E Explained
Command-Line Interface
pip install "colorfyi[cli]"
colorfyi info FF6B35 # Full color info (7 spaces)
colorfyi contrast 000000 FFFFFF # WCAG contrast check
colorfyi harmonies FF6B35 # Color harmonies
colorfyi shades 3B82F6 # Tailwind shade palette
colorfyi blindness FF5733 # Color blindness simulation
colorfyi mix FF0000 0000FF # Mix two colors
colorfyi compare FF6B35 3498DB # Compare (Delta E)
colorfyi gradient FF0000 0000FF # Smooth gradient
MCP Server (Claude, Cursor, Windsurf)
Add color tools to any AI assistant that supports Model Context Protocol.
pip install "colorfyi[mcp]"
Add to your claude_desktop_config.json:
{
"mcpServers": {
"colorfyi": {
"command": "uvx",
"args": ["--from", "colorfyi[mcp]", "python", "-m", "colorfyi.mcp_server"]
}
}
}
9 tools available: color_info, contrast_check, color_harmonies, color_shades, simulate_color_blindness, mix_colors, compare_colors, gradient, text_color_for_background
REST API Client
pip install "colorfyi[api]"
from colorfyi.api import ColorFYI
with ColorFYI() as api:
info = api.color("FF6B35") # GET /api/color/FF6B35/
cr = api.contrast("000", "FFF") # GET /api/contrast/?fg=000&bg=FFF
shades = api.shades("3B82F6") # GET /api/shades/3B82F6/
palette = api.palette("FF6B35") # GET /api/palette/FF6B35/
Full API documentation with OpenAPI spec at colorfyi.com/api/openapi.json.
API Reference
Color Conversion
| Function | Description |
|---|---|
hex_to_rgb(hex) -> RGB |
HEX to RGB |
rgb_to_hex(r, g, b) -> str |
RGB to HEX |
rgb_to_hsl(r, g, b) -> HSL |
RGB to HSL |
hsl_to_rgb(h, s, l) -> RGB |
HSL to RGB |
rgb_to_hsv(r, g, b) -> HSV |
RGB to HSV |
rgb_to_cmyk(r, g, b) -> CMYK |
RGB to CMYK |
rgb_to_lab(r, g, b) -> Lab |
RGB to CIE Lab |
lab_to_rgb(l, a, b) -> RGB |
CIE Lab to RGB |
rgb_to_oklch(r, g, b) -> OKLCH |
RGB to OKLCH |
get_color_info(hex) -> ColorInfo |
All 7 color spaces at once |
WCAG Contrast
| Function | Description |
|---|---|
contrast_ratio(hex1, hex2) -> ContrastResult |
WCAG 2.1 contrast ratio + AA/AAA checks |
relative_luminance(r, g, b) -> float |
Relative luminance (0–1) |
text_color_for_bg(hex) -> str |
Best text color (black or white) for a background |
Harmonies & Palettes
| Function | Description |
|---|---|
harmonies(hex) -> HarmonySet |
All 5 harmony types |
complementary(hex) -> list[str] |
Complementary colors |
analogous(hex) -> list[str] |
Analogous colors |
triadic(hex) -> list[str] |
Triadic colors |
split_complementary(hex) -> list[str] |
Split-complementary |
tetradic(hex) -> list[str] |
Tetradic (rectangular) |
Shades & Scales
| Function | Description |
|---|---|
generate_shades(hex) -> list[ShadeStep] |
Tailwind-style 50–950 |
lightness_scale(hex, steps) -> list[ShadeStep] |
Vary lightness only |
saturation_scale(hex, steps) -> list[ShadeStep] |
Vary saturation only |
hue_shift_scale(hex, steps) -> list[str] |
Rotate through hue spectrum |
monochromatic(hex, count) -> list[str] |
Monochromatic palette |
Comparison & Mixing
| Function | Description |
|---|---|
delta_e(hex1, hex2) -> float |
CIE76 perceptual distance |
compare_colors(hex1, hex2) -> CompareResult |
Full comparison report |
mix_colors(hex1, hex2, ratio) -> str |
Perceptual mixing in Lab space |
gradient_steps(hex1, hex2, steps) -> list[str] |
Smooth gradient |
simulate_color_blindness(hex) -> ColorBlindResult |
4 types of CVD simulation |
Learn More About Color
- Tools: Color Converter · Contrast Checker · Palette Generator · Shade Generator · Blindness Simulator · Gradient Generator
- Color Systems: CSS Named Colors · Pantone Colors · Tailwind Colors · RAL Colors
- Brand Colors: 544 Brand Palettes · Google · Apple · Meta
- Guides: Color Theory Glossary · Blog
- API: REST API Docs · OpenAPI Spec
Also Available
| Platform | Install | Link |
|---|---|---|
| npm | npm install @fyipedia/colorfyi |
npm |
| Homebrew | brew tap fyipedia/tap && brew install fyipedia |
Tap |
| MCP | uvx --from "colorfyi[mcp]" python -m colorfyi.mcp_server |
Config |
| VSCode | ext install fyipedia.colorfyi-vscode |
Marketplace |
FYIPedia Developer Tools
Part of the FYIPedia open-source developer tools ecosystem.
| Package | PyPI | npm | Description |
|---|---|---|---|
| colorfyi | PyPI | npm | Color conversion, WCAG contrast, harmonies — colorfyi.com |
| emojifyi | PyPI | npm | Emoji encoding & metadata for 3,781 emojis — emojifyi.com |
| symbolfyi | PyPI | npm | Symbol encoding in 11 formats — symbolfyi.com |
| unicodefyi | PyPI | npm | Unicode lookup with 17 encodings — unicodefyi.com |
| fontfyi | PyPI | npm | Google Fonts metadata & CSS — fontfyi.com |
| distancefyi | PyPI | npm | Haversine distance & travel times — distancefyi.com |
| timefyi | PyPI | npm | Timezone ops & business hours — timefyi.com |
| namefyi | PyPI | npm | Korean romanization & Five Elements — namefyi.com |
| unitfyi | PyPI | npm | Unit conversion, 220 units — unitfyi.com |
| holidayfyi | PyPI | npm | Holiday dates & Easter calculation — holidayfyi.com |
| cocktailfyi | PyPI | — | Cocktail ABV, calories, flavor — cocktailfyi.com |
| fyipedia | PyPI | — | Unified CLI: fyi color info FF6B35 — fyipedia.com |
| fyipedia-mcp | PyPI | — | Unified MCP hub for AI assistants — fyipedia.com |
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colorfyi-0.2.1.tar.gz.
File metadata
- Download URL: colorfyi-0.2.1.tar.gz
- Upload date:
- Size: 434.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d6e56484accb51d8366ce17d47908de592e2de086f000271277fd3ba2bc2d96
|
|
| MD5 |
83e10d2386a13583d798ffcf5ab97912
|
|
| BLAKE2b-256 |
e7239421826969062c6e7c430dfc18e9ce3e27923af6b6d76f6aacd642fde244
|
File details
Details for the file colorfyi-0.2.1-py3-none-any.whl.
File metadata
- Download URL: colorfyi-0.2.1-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.8 {"installer":{"name":"uv","version":"0.10.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96c36c8e7e15a23632f23509fa368b36760355ea1349cdcaaaa148ff497076ba
|
|
| MD5 |
7c576383b85e2d050d4b36b6afeac2c5
|
|
| BLAKE2b-256 |
f35bbd8a131dd866b34241542d0da6913a4fe0ac611582f065074cd1b0f9da30
|