https://github.com/qtiptip/pylette
A Python library for extracting color palettes from supplied images.
https://github.com/qtiptip/pylette
color color-palette color-scheme colorpicker command-line-interface image-analysis image-processing pillow python visualization-tools
Last synced: 5 months ago
JSON representation
A Python library for extracting color palettes from supplied images.
- Host: GitHub
- URL: https://github.com/qtiptip/pylette
- Owner: qTipTip
- License: mit
- Created: 2018-08-17T14:37:49.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2025-04-07T10:30:05.000Z (6 months ago)
- Last Synced: 2025-04-12T17:49:13.147Z (6 months ago)
- Topics: color, color-palette, color-scheme, colorpicker, command-line-interface, image-analysis, image-processing, pillow, python, visualization-tools
- Language: Python
- Homepage: https://qtiptip.github.io/Pylette/
- Size: 2.47 MB
- Stars: 135
- Watchers: 2
- Forks: 12
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
- Citation: CITATION.cff
Awesome Lists containing this project
README
Welcome to Pylette, the easy-to-use Python library for extracting color palettes from images!
[](https://badge.fury.io/py/Pylette)
[](http://pepy.tech/project/pylette)
[](https://squidfunk.github.io/mkdocs-material/)

[](https://doi.org/10.5281/zenodo.14757252)---
**Documentation**: [qtiptip.github.io/Pylette](https://qtiptip.github.io/Pylette/)
**Source code:** [qTipTip/Pylette](https://github.com/qTipTip/Pylette)
---
## What is Pylette?
Pylette is a powerful yet user-friendly library designed to help you extract color palettes from images. Whether you're
working on computer graphics, visualizations, or generative art, Pylette makes it easy to create visually appealing
color sets.Key features:
* Extract color palettes from images
* Support for various color modes (RGB, RGBa, HSV, etc.)
* Random color selection from palettes
* Command-line interface for quick palette extraction## Getting Started
### Installation
You can easily install Pylette using pip:
```shell
pip install Pylette
```Or if you prefer using Poetry:
```shell
poetry add Pylette
```### Quick Start Guide
Here's how to extract a color palette from an image and work with it in Python:
```python
from Pylette import extract_colorspalette = extract_colors(image='image.jpg', palette_size=10)
# Access colors by index
most_common_color = palette[0]
least_common_color = palette[-1]# Get color information
print(most_common_color.rgb)
print(most_common_color.hls)
print(most_common_color.hsv)# Display the palette, and save the image to file
palette.display(save_to_file=True)# Save palette's color values to CSV
palette.to_csv(filename='color_palette.csv', frequency=True)# Pick random colors
random_color = palette.random_color(N=1, mode='uniform')
random_colors = palette.random_color(N=100, mode='frequency')
```This will give you a palette of 10 colors, sorted by frequency.
The image is automatically resized to 256x256 pixels for faster processing.
See the [documentation](https://qtiptip.github.io/Pylette) for a complete list of available methods and attributes.## Command Line Interface:
Pylette also comes with a command-line interface for quick palette extraction:
```shell
pylette --helpUsage: pylette [OPTIONS]
╭─ Options ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ --filename PATH [default: None] │
│ --image-url TEXT [default: None] │
│ --mode [KM|MC] [default: KM] │
│ --n INTEGER [default: 5] │
│ --sort-by [frequency|luminance] [default: luminance] │
│ --stdout --no-stdout [default: stdout] │
│ --out-filename PATH [default: None] │
│ --display-colors --no-display-colors [default: no-display-colors] │
│ --colorspace [rgb|hsv|hls] [default: rgb] │
│ --install-completion Install completion for the current shell. │
│ --show-completion Show completion for the current shell, to copy it or customize the installation. │
│ --help Show this message and exit. │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```