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 (returns Oklab object by default)
result = converter.convert("#FF0000") 
print(result.L) 
# 0.6279...

# Request Oklch explicitly
oklch = converter.convert("#FF0000", return_type="oklch")
print(oklch.h)
# 29.23...

# Request both (legacy behavior)
all_results = converter.convert("#FF0000", return_type="all")
print(all_results['oklab'].L)

Tuple Input

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

# Convert from RGB Tuple
white = converter.convert((255, 255, 255))
print(white.L)
# 1.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.2.0.tar.gz (5.1 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.2.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for colorswan-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c8acf55d84a2f0ac8e86f2419cfdb518d7436a5379f61dc0192564fd7c5c0221
MD5 5ca4a6c73d0ed87fc34501a796ca0eb5
BLAKE2b-256 5ec23af58994a1a95656bfd8a3493c9b47002dd4d96de9ecae362bba7183a771

See more details on using hashes here.

File details

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

File metadata

  • Download URL: colorswan-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.2 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72be9df16022b0abdfa73403465c80aef96957d0f1ff66fa65beacf7f8da9a4a
MD5 46307a6c65f5bb3acf493a97c852f481
BLAKE2b-256 b72e6326e6f02d6e8a85ae34e04e1e2b427898b4f875f48dc7d57b6fff7fa0f0

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