Skip to main content

You pick your colors, we make it readable

Project description

CM-Colors 🎨✨

Python Tests PyPI - Version GitHub stars Downloads License

Color contrast that works for everyone

CM-Colors automatically finds colors that look good and read well, so your website works for all visitors. Use it to fix your CSS files or as a Python tool to adjust colors in your code.

The percentage shows how much easier the text is to read:

an image showing side by side comparision of before and after change of colors

Overview

Tired of guessing which colors work together? CM-Colors fixes color contrast automatically. It finds similar colors that are easy to read, so you can get back to building features instead of adjusting colors.

What it does:

  • Automatically makes your colors readable for everyone
  • Fixes all your CSS files in one go
  • Works with any color format you use (hex, RGB, named colors)
  • Keeps your design looking great while making it accessible

Installation

pip install cm-colors

CLI Usage

The cm-colors command checks your CSS files and fixes colors that are hard to read.

Basic commands

Fix a single CSS file:

cm-colors style.css

Fix all CSS files in a folder:

cm-colors path/to/styles/

Fix files in the current folder:

cm-colors .

Options

--default-bg COLOR

Sets the background color to use if one isn't specified.

Default: white

Example:

cm-colors styles.css --default-bg "#f5f5f5"


`--mode <0|1|2>`

Choose your optimization strategy:
- `0` (Ultra Strict): Minimal changes, strict Delta E.
- `1` (Default): Balanced approach, recursive tuning.
- `2` (Relaxed): More aggressive changes if needed.

`--premium`

Aim for AAA compliance (contrast ratio 7.0) instead of AA (4.5).

Example:

```bash
cm-colors styles.css --mode 2 --premium

Output

Updated CSS files:

We create new files with _cm added to the name, so your original files stay safe.

  • Input: style.css
  • Output: style_cm.css

HTML report:

If we change any colors, we'll create a cm_colors_report.html file showing you exactly what changed and why.

Console output:

Processing 3 files...

Results:
✓ 12 colors already readable
✓ 5 colors adjusted for better readability
✗ 2 colors need your attention

Could not tune 2 pairs:
  style.css -> .warning-badge
    Reason: Couldn't find a similar color that's easy to read
  layout.css -> .subtle-text
    Reason: Try starting with different colors

Report generated: /path/to/cm_colors_report.html

Python API

ColorPair class

Check and fix colors in your Python code:

from cm_colors import ColorPair

# Create a color pair
pair = ColorPair("#5f7887", "rgb(230, 240, 245)")

# Check if it's readable
print(f"Readable: {pair.is_readable}")  # False

# Fix colors automatically
tuned_text, success = pair.tune_colors()
print(f"New color: {tuned_text}")       # rgb(83, 107, 122)
print(f"Fixed: {success}")              # True

Advanced Options

You can control how we fix your colors:

# Use 'premium' mode to aim for the highest readability standard (AAA)
tuned_text, success = pair.tune_colors(premium=True)

# Choose how strict we should be about changing the color shade
# mode=0: Ultra Strict (changes color very little)
# mode=1: Default (best balance of readability and style)
# mode=2: Relaxed (allows more change to ensure readability)
tuned_text, success = pair.tune_colors(mode=2)

# See a visual comparison in your terminal
tuned_text, success = pair.tune_colors(show=True)

# Generate a detailed HTML report
tuned_text, success = pair.tune_colors(html=True)

Color class

Work with individual colors easily:

from cm_colors import Color

# Create colors from any format
color = Color("#c7483b")

# Convert to other formats
if color.is_valid:
    print(color.to_rgb_string())  # 'rgb(199, 72, 59)'
    print(color.to_hex())         # #c7483b

Documentation

For more details, see the full documentation.

License

GNU General Public License v3.0

Support

Found a problem? Let us know.


Stop guessing, start building.

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

cm_colors-0.4.3.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cm_colors-0.4.3-py3-none-any.whl (53.9 kB view details)

Uploaded Python 3

File details

Details for the file cm_colors-0.4.3.tar.gz.

File metadata

  • Download URL: cm_colors-0.4.3.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cm_colors-0.4.3.tar.gz
Algorithm Hash digest
SHA256 f73ca26ea54402a3be45504d292f1fd6e679f4f9289713af8c49fc6c1fc46b92
MD5 3082524242cdb0d782c3249a80b7a40c
BLAKE2b-256 b27c339ff14f979fbac933b3d6a7e1705bc53c85a065da02467ca080e82237ad

See more details on using hashes here.

File details

Details for the file cm_colors-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: cm_colors-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 53.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for cm_colors-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 235af3e1088c9160e008a021d32bd57fbea9c29cff0db9c95f6b8ccc3cf5f515
MD5 3f57f028514fcde70fe60fd759db7a13
BLAKE2b-256 6cacbe734a9605f20e3d8e67126e0ce2ad098deb8ea5f0ace6055c64157ab549

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page