# color-contrast
A python library to calculate and modulate color contrasts according to WCAG2.1
![PyPI - Version](https://img.shields.io/pypi/v/color-contrast?style=for-the-badge&logo=pypi)
![GitHub Tag](https://img.shields.io/github/v/tag/ZugBahnHof/color-contrast?style=for-the-badge&logo=github)
![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/ZugBahnHof/color-contrast?style=for-the-badge&logo=github)
## Usage
Install `color-contrast` into your python environment, using:
```shell
pip install color-contrast
```
After installing, you can use the project as follows:
```python
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:
```python
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](before.png)
![After](after.png)
## Contributing
To set the development environment up, follow the following steps.
Make sure you have poetry installed.
```shell
# 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:
```shell
# Run the linter
ruff check
# Reformat
ruff check --fix
ruff format
# Run the test cases
python -m unittest tests
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ZugBahnHof/color-contrast",
"name": "color-contrast",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "color, colour, accessibility, wcag, wcag2.1",
"author": "Julian Leucker",
"author_email": "leuckerj@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/46/33/c06f94b4eb048c59f0ad2640d822eb33e01bfb128a27b33a65fe93f47419/color_contrast-0.1.0.tar.gz",
"platform": null,
"description": "# color-contrast\nA python library to calculate and modulate color contrasts according to WCAG2.1\n\n![PyPI - Version](https://img.shields.io/pypi/v/color-contrast?style=for-the-badge&logo=pypi)\n![GitHub Tag](https://img.shields.io/github/v/tag/ZugBahnHof/color-contrast?style=for-the-badge&logo=github)\n![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/ZugBahnHof/color-contrast?style=for-the-badge&logo=github)\n\n## Usage\n\nInstall `color-contrast` into your python environment, using:\n\n```shell\npip install color-contrast\n```\n\nAfter installing, you can use the project as follows:\n\n```python\n\nfrom colour import Color\n\nfrom color_contrast import AccessibilityLevel, check_contrast\n\nbg = Color(\"#123456\")\n\ncheck_contrast(\"#404040\", bg, level=AccessibilityLevel.AA18) # True\n\ncheck_contrast(\"#404040\", bg, level=AccessibilityLevel.AA) # False\n\ncheck_contrast(\"white\", bg, level=AccessibilityLevel.AAA) # True\n\ncheck_contrast(Color(hsl=(1, 1, 1)), bg) # True\n```\n\nOr if you want to modulate the colors automatically:\n\n```python\nfrom color_contrast import modulate, ModulationMode\n\nmodulate(\"5d3eb2\", \"5d3eb2\", mode=ModulationMode.BOTH)\n# Returns:\n# <Color: #32215f>, <Color: #9e89d6>, true\n```\n\nThis example used the same foreground and background color, this is the before and after:\n\n![Before](before.png)\n![After](after.png)\n\n## Contributing\n\nTo set the development environment up, follow the following steps.\nMake sure you have poetry installed.\n\n```shell\n# Clone the repository\ngit clone git@github.com:ZugBahnHof/color-contrast.git\n\ncd color-contrast\n\n# Activate the virtual environment\npoetry shell\n\n# Install the requirements\npoetry install\n\n# Activate the commit hooks\npre-commit install \n```\n\nUseful commands:\n\n```shell\n# Run the linter\nruff check\n\n# Reformat\nruff check --fix\nruff format\n\n# Run the test cases\npython -m unittest tests\n```\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "Python library to calculate and modulate color contrasts according to WCAG2.1",
"version": "0.1.0",
"project_urls": {
"Homepage": "https://github.com/ZugBahnHof/color-contrast",
"Repository": "https://github.com/ZugBahnHof/color-contrast"
},
"split_keywords": [
"color",
" colour",
" accessibility",
" wcag",
" wcag2.1"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "7054d85287d9550f649a7034655d8c5918244f979efad6e70a67dfbfacbfae38",
"md5": "e4d6b6cc9e382550fe3a61a0fca8ab3f",
"sha256": "fcbf3e3bb9f4ad87af95acf9945f8505aa668f660d5a20843e7d7d65fda21756"
},
"downloads": -1,
"filename": "color_contrast-0.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "e4d6b6cc9e382550fe3a61a0fca8ab3f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 3384,
"upload_time": "2024-06-27T15:19:50",
"upload_time_iso_8601": "2024-06-27T15:19:50.816679Z",
"url": "https://files.pythonhosted.org/packages/70/54/d85287d9550f649a7034655d8c5918244f979efad6e70a67dfbfacbfae38/color_contrast-0.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4633c06f94b4eb048c59f0ad2640d822eb33e01bfb128a27b33a65fe93f47419",
"md5": "9559390e08e2d8a1f60b8a2536ff9852",
"sha256": "cb9cd0c09b3000e4ebeefe5da3c0f81ca7c9f5d60212b7473f1c2b41eb7e4b81"
},
"downloads": -1,
"filename": "color_contrast-0.1.0.tar.gz",
"has_sig": false,
"md5_digest": "9559390e08e2d8a1f60b8a2536ff9852",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 2837,
"upload_time": "2024-06-27T15:19:52",
"upload_time_iso_8601": "2024-06-27T15:19:52.786216Z",
"url": "https://files.pythonhosted.org/packages/46/33/c06f94b4eb048c59f0ad2640d822eb33e01bfb128a27b33a65fe93f47419/color_contrast-0.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-27 15:19:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ZugBahnHof",
"github_project": "color-contrast",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "color-contrast"
}