A dead-simple tool to extract a strong, distinct palette from any image.
Project description
principal_colors
principal_colors is a dead-simple tool to extract a strong, distinct palette from any image.
It is designed around one obvious path for normal users:
principal-colors path/to/image.jpg
That prints the palette to stdout and also writes a single JSON file next to the image, such as:
image.palette.json
Under the hood, it uses OKLab distances and can optionally account for common color-vision deficiencies, but those are secondary features rather than the headline.
Why this rewrite
This package has been rewritten around a simpler public UX:
- standard CLI flags instead of
key=value - a positional image path
- no import-time side effects
- a clean Python API for both simple and detailed use
- a small dependency footprint: just NumPy and Pillow
- feature-rich advanced exports without cluttering the default experience
Installation
From PyPI:
pip install principal-colors
From a local checkout:
pip install .
For development:
python -m pip install -e '.[dev]'
Command line usage
The basic path is:
principal-colors image.jpg
That will:
- print the palette as hex colors to stdout
- save
image.palette.json
Basic examples
principal-colors image.jpg
principal-colors image.jpg --colors 10
principal-colors image.jpg --stdout-only
principal-colors image.jpg --output my_palette.json
Advanced examples
principal-colors image.jpg --cb-mode all
principal-colors image.jpg --save-formats json,svg,png --output-prefix out/palette
principal-colors image.jpg --print-format rgb
principal-colors image.jpg --details
No arguments
If you run:
principal-colors
it shows an overview, a manual, and an ASCII logo.
Python API
The simple API returns hex colors by default:
from principal_colors import extract_palette
colors = extract_palette("image.jpg")
print(colors)
You can ask for other return types:
from principal_colors import extract_palette
rgb_colors = extract_palette("image.jpg", return_format="rgb")
result = extract_palette("image.jpg", return_format="result")
Or use the detailed API directly:
from principal_colors import extract_palette_result
result = extract_palette_result("image.jpg", num_colors=10)
print(result.hex_colors)
print(result.rgb_colors)
print(result.oklab_colors)
result.save() # writes image.palette.json
result.save_many(["json", "svg", "png"], output_prefix="out/palette")
Public low-level helpers
The lower-level functions are intentionally public, so advanced users can do things like:
from principal_colors import rgb_to_oklab, oklab_to_rgb, simulate_cb
Output formats
The package can write:
- JSON
- TXT
- CSV
- SVG
- PNG swatches
- CSS variables
- Tailwind JSON
- Matplotlib style files
- GIMP palette files
The default automatic save format is JSON because it is a reasonable, machine-readable single-file default.
API docs
A small API reference lives in docs/API.md.
Development
Run checks with:
ruff check .
pytest
python -m build
python -m twine check dist/*
License
MIT.
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 principal_colors-0.2.0.tar.gz.
File metadata
- Download URL: principal_colors-0.2.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
64d5b835cf688e13387c763c76fb009644171f9f24c8a95e707209990ec2985e
|
|
| MD5 |
86b1d54cd6717396bbfbb881f7b6947a
|
|
| BLAKE2b-256 |
2f79531b707df0696abbc40063accd11b5ed8294b84150bb5bb6732bc6e05d66
|
Provenance
The following attestation bundles were made for principal_colors-0.2.0.tar.gz:
Publisher:
publish-pypi.yml on nialljmiller/principal_colors
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
principal_colors-0.2.0.tar.gz -
Subject digest:
64d5b835cf688e13387c763c76fb009644171f9f24c8a95e707209990ec2985e - Sigstore transparency entry: 1244140930
- Sigstore integration time:
-
Permalink:
nialljmiller/principal_colors@a2d7e883c90b87714259fcea1815aff40925e543 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/nialljmiller
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@a2d7e883c90b87714259fcea1815aff40925e543 -
Trigger Event:
push
-
Statement type:
File details
Details for the file principal_colors-0.2.0-py3-none-any.whl.
File metadata
- Download URL: principal_colors-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2bfff402bb99bdc02a65b11125c089c357bd3a6b1df42f59e0e06992149aa27
|
|
| MD5 |
a5fe05d8209b4e82f0eb1abb1852c6ac
|
|
| BLAKE2b-256 |
d57f0de3939d5ba95c0c67ad414f2c46d6775b9bc094d2557482573968dde8bc
|
Provenance
The following attestation bundles were made for principal_colors-0.2.0-py3-none-any.whl:
Publisher:
publish-pypi.yml on nialljmiller/principal_colors
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
principal_colors-0.2.0-py3-none-any.whl -
Subject digest:
e2bfff402bb99bdc02a65b11125c089c357bd3a6b1df42f59e0e06992149aa27 - Sigstore transparency entry: 1244140937
- Sigstore integration time:
-
Permalink:
nialljmiller/principal_colors@a2d7e883c90b87714259fcea1815aff40925e543 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/nialljmiller
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@a2d7e883c90b87714259fcea1815aff40925e543 -
Trigger Event:
push
-
Statement type: