Skip to main content

Python library to calculate and modulate color contrasts according to WCAG2.1

Project description

color-contrast

A python library to calculate and modulate color contrasts according to WCAG2.1

PyPI - Version GitHub Tag GitHub Issues or Pull Requests PyPI - License

Usage

Install color-contrast into your python environment, using:

pip install color-contrast

After installing, you can use the project as follows:

from colour import Color

from color_contrast import AccessibilityLevel, check_contrast

bg = Color("#123456")

check_contrast("#404040", bg, level=AccessibilityLevel.AA18)  # True

check_contrast("#404040", bg, level=AccessibilityLevel.AA)  # False

check_contrast("white", bg, level=AccessibilityLevel.AAA)  # True

check_contrast(Color(hsl=(1, 1, 1)), bg)  # True

Or if you want to modulate the colors automatically:

from color_contrast import modulate, ModulationMode

modulate("5d3eb2", "5d3eb2", mode=ModulationMode.BOTH)
# Returns:
# <Color: #32215f>, <Color: #9e89d6>, true

This example used the same foreground and background color, this is the before and after:

Before After

Contributing

To set the development environment up, follow the following steps. Make sure you have poetry installed.

# Clone the repository
git clone git@github.com:ZugBahnHof/color-contrast.git

cd color-contrast

# Activate the virtual environment
poetry shell

# Install the requirements
poetry install

# Activate the commit hooks
pre-commit install 

Useful commands:

# Run the linter
ruff check

# Reformat
ruff check --fix
ruff format

# Run the test cases
python -m unittest tests

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

color_contrast-0.1.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

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

color_contrast-0.1.1-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file color_contrast-0.1.1.tar.gz.

File metadata

  • Download URL: color_contrast-0.1.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.6 Linux/6.12.17-amd64

File hashes

Hashes for color_contrast-0.1.1.tar.gz
Algorithm Hash digest
SHA256 168d823434293a3e625a239ae03cfbc7371de695c873979d85df24e776c204cf
MD5 6b5a752111f41baa9b6a5df65b87e5ef
BLAKE2b-256 f5d113ca64af15b9abf4dd3daf8d69aa0705a43169d7e493fe3f47d276691416

See more details on using hashes here.

File details

Details for the file color_contrast-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: color_contrast-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.6 Linux/6.12.17-amd64

File hashes

Hashes for color_contrast-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9a8f379e29a813ebcca0196bb8a90ce46fec63615ce68a534b2d6719afb4099d
MD5 c5b0fff9ec98a1f2bb752ce42326173f
BLAKE2b-256 a8a260889952b11c1a9443c467b874a8383a737e2c8287171c2c61df3c3397bb

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