Skip to main content

lightweight python implementation of Björn Ottosson's oklab colour space

Project description

lightweight python implementation of Björn Ottosson's oklab/oklch colour space.

i like oklab but there isnt a straightforward python package for working with it. so i made it.

install

install it from PyPI:

python -m pip install oklab

how to use?

use it in python:

import oklab

oklab.lch_to_hex((0.75, 0.125, 310.0))
# '#c697e9'

oklab.hex_to_lch('#ff0000')
# (0.6279536182521783, 0.25762679148825324, 29.227131291763712)

oklab.lab_to_xyz((1.0, 0.0, 0.0))
# (0.9504559270516719, 0.9999999999999998, 1.0890577507598782)

or use it in the terminal:

> oklab -i lch -o hex 0.75 0.125 310
#c697e9

> oklch ff0000
(0.6279536182521783 0.25762679148825324 29.227131291763712)

> oklab -i lab -o xyz 1.0 0.0 0.0
(0.9504559270516719, 0.9999999999999998, 1.0890577507598782)

features

  • ✅ 6 formats: rgb, hex, lab, lch, xyz, lms
  • ✅ 30 conversion functions (complete graph)
  • ✅ numerical accuracy + roundtrip correctness
  • ✅ source correctness
  • ✅ zero dependencies
  • ✅ CLI tool
  • ✅ python ≥3.8 compatibility
  • 🚧 clamping (in native oklab space via chroma reduction)
  • 🚧 configurable RGB primaries (P3, rec2020, …)
  • ❌ CMYK support (scope creep)

sources

conversion graph

here is a graph of the atomic conversions:

graph of formats and conversions

  • lab: oklab cartesian space
  • lch: oklch cylindrical space
  • lms: intermediate lms-like space
  • xyz: CIEXYZ space
  • rgb: sRGB
  • hex: 8-bit sRGB in hexadecimal

all composed conversions are derived via shortest path in this graph

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

oklab-0.2.1.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

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

oklab-0.2.1-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file oklab-0.2.1.tar.gz.

File metadata

  • Download URL: oklab-0.2.1.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for oklab-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9c1dd09ab91797ccf224271dca987f1ed487038be37310df795611d10c278880
MD5 64307c7d45cd60e81039affb34116609
BLAKE2b-256 54927ecc99feff14dfcbc181d2618a11548fcfdd044ae77f1ba32d4216cd1548

See more details on using hashes here.

File details

Details for the file oklab-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: oklab-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for oklab-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 600a81b30aca1e51a9a71d472dc770f67e2f7add7efa422af875b672ef51d079
MD5 0d63869184a5ffdbd3315b71de8c4a8e
BLAKE2b-256 31cbb2c7a8c980f26e3438b3326253bbc4f7443830b239154ee43c7859e94bce

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