Skip to main content

Precision color conversion library (sRGB to Oklab/Oklch)

Project description

colorswan

colorswan is a precision color conversion library for Python, focused on converting sRGB to the perceptual color spaces Oklab and Oklch.

It provides accurate conversions using standard white points and matrices, suitable for color science, data visualization, and web design applications.

Installation

pip install colorswan

Usage

Basic Conversion (Hex to Oklab/Oklch)

from colorswan import OkColor

converter = OkColor()

# Convert from Hex
result = converter.convert("#FF0000") # Red
print(result)
# Output:
# {
#   'oklab': {'L': 0.6279..., 'a': 0.2248..., 'b': 0.1258...},
#   'oklch': {'L': 0.6279..., 'C': 0.2576..., 'h': 29.233...}
# }

Tuple Input

You can also pass RGB tuples (0-255).

# Convert from RGB Tuple
white = converter.convert((255, 255, 255))
print(white['oklab'])
# {'L': 1.0, 'a': 0.0, 'b': 0.0}

Using Constants

The library exposes standard color matrices and white points.

from colorswan import constants

print(constants.WHITE_POINT_D65)
# (0.95047, 1.0, 1.08883)

Features

  • Accurate: Implements the official Oklab matrices (sRGB -> Linear -> XYZ -> LMS -> Oklab).
  • Zero Dependencies: Pure Python implementation.
  • Easy to Use: Simple API for common color tasks.

License

MIT

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

colorswan-0.0.4.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

colorswan-0.0.4-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file colorswan-0.0.4.tar.gz.

File metadata

  • Download URL: colorswan-0.0.4.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for colorswan-0.0.4.tar.gz
Algorithm Hash digest
SHA256 bddd9abeb58a0b29f5e66b9e2e46c57c30016e5b10b5acba51e709a2de535f58
MD5 862998cfd4b0493910c0e2ad8a1bb06a
BLAKE2b-256 66920573900a121dbd60db39d8e00e860bfbf37be1980c56ccdbe8fa21f65588

See more details on using hashes here.

File details

Details for the file colorswan-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: colorswan-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for colorswan-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9e220567d8e497af01fb20797d2836a1167998ecdd637fc061b04e33890ec6f4
MD5 ca1a1077d386799db0a1fe95b827b257
BLAKE2b-256 b01ab2bfb1b46bf0f486917bf3312852e9f59902683ccebe0bd94f89c9315e45

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