Utilities for working with colors and Plotly-friendly palettes.
Project description
san-diego
Small Python utilities for working with colors, image palettes, and Plotly-friendly color output.
Install with pip install san-diego and import with import sd.
Notebook Workflow
There is a starter notebook at notebooks/color_playground.ipynb.
Install notebook tooling:
uv sync --group dev
Launch JupyterLab:
uv run --group dev jupyter lab
Features
- Extract dominant colors from an image.
- Convert between RGB, HEX, and HSL.
- Lighten or darken a color by a percentage.
- Build Plotly colorscales and color sequences.
- Save, load, and reuse named color schemes with consistent roles.
- Use
ColorandColorScaleclasses for structured color handling.
Example
from sd import (
Color,
ColorScheme,
ColorScale,
build_plotly_colorscale,
build_plotly_colorscale_from_scheme,
color_swatches,
get_color_scheme,
extract_dominant_colors,
extract_dominant_hex_colors,
list_color_scheme_roles,
save_color_scheme,
)
brand = Color.from_hex("#1f77b4")
brand.to_rgb()
# (31, 119, 180)
brand.to_hsl()
# (204.6, 0.706161, 0.413725)
brand.lighten(20).to_hex()
# '#4c92c3'
brand.as_plotly_rgb()
# 'rgb(31, 119, 180)'
scale = ColorScale.from_colors(["#0d3b66", "#faf0ca", "#f95738"])
scale.to_plotly()
# [[0.0, '#0d3b66'], [0.5, '#faf0ca'], [1.0, '#f95738']]
build_plotly_colorscale(["#000000", "#ffffff"])
# [[0.0, '#000000'], [1.0, '#ffffff']]
extract_dominant_colors("example.png", count=3)
# [Color(...), Color(...), Color(...)]
extract_dominant_hex_colors("example.png", count=3)
# ['#...', '#...', '#...']
color_swatches(["#1f77b4", "rgb(255, 127, 14)", (44, 160, 44)])
# In Jupyter, renders labeled color swatches.
scheme = get_color_scheme("ocean")
list_color_scheme_roles()
# ['primary', 'secondary', 'accent', 'dark', 'light', 'blue', 'purple', 'red', 'orange', 'yellow', 'green']
scheme.to_hex_map()
# {
# 'primary': '#3a506b',
# 'secondary': '#5bc0be',
# 'accent': '#c5f3f0',
# 'dark': '#0b132b',
# 'light': '#e9fffe',
# 'blue': '#3a6ea5',
# 'purple': '#6a4c93',
# 'red': '#c44536',
# 'orange': '#d97d54',
# 'yellow': '#d8c36a',
# 'green': '#4c956c',
# }
save_color_scheme(
"brand",
{
"primary": "#112233",
"secondary": "#445566",
"accent": "#778899",
"dark": "#0a0f14",
"light": "#f5f7fa",
"blue": "#4f74c8",
"purple": "#7f5ab6",
"red": "#bf4b4b",
"orange": "#d88752",
"yellow": "#d8c15e",
"green": "#4d8b68",
},
"brand.json",
)
ColorScheme.from_reference("brand.json").to_plotly_colorscale()
# [[0.0, '#112233'], [0.1, '#445566'], [0.2, '#778899'], [0.3, '#0a0f14'], [0.4, '#f5f7fa'], [0.5, '#4f74c8'], [0.6, '#7f5ab6'], [0.7, '#bf4b4b'], [0.8, '#d88752'], [0.9, '#d8c15e'], [1.0, '#4d8b68']]
build_plotly_colorscale_from_scheme("sunset")
# [[0.0, '#e9724c'], [0.1, '#ffc857'], [0.2, '#c5283d'], [0.3, '#1f2041'], [0.4, '#fff1d6'], [0.5, '#4d6cfa'], [0.6, '#7b5ea7'], [0.7, '#c5283d'], [0.8, '#e9724c'], [0.9, '#ffc857'], [1.0, '#7aa67a']]
Project details
Release history Release notifications | RSS feed
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 san_diego-0.1.0.tar.gz.
File metadata
- Download URL: san_diego-0.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4ce3256a74cdf6b126be9d1cc37492c2593c7a9f393961940f30203a5aaee9d
|
|
| MD5 |
b88cba647c6a2c4bb292a4dc8ec600f4
|
|
| BLAKE2b-256 |
d9feabe15229172852044cb1dce022cbd37bbf9215dcb270a9a2b08ddc97879b
|
File details
Details for the file san_diego-0.1.0-py3-none-any.whl.
File metadata
- Download URL: san_diego-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fd1f27bc475153c61209cfa289591a864b2a04668b0857575780721d97525f7
|
|
| MD5 |
9c5436a6c04ce69803efb92c43ce601f
|
|
| BLAKE2b-256 |
283ed796c14f12cd9a45170951ff9cda5844ffa135c969c811ad2226552123b0
|