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?

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)

features

  • 6 formats: rgb, hex, lab, lch, xyz, lms
  • 30 conversion functions (complete graph)
  • numerical accuracy + roundtrip precision
  • source correctness
  • zero dependencies
  • python 3.8–3.14 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.1.1.tar.gz (23.7 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.1.1-py2.py3-none-any.whl (5.7 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for oklab-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a68c8d4f7612b0d0809b18988b56e9338103ba7a4c1b600a7b4dd7193568c855
MD5 6e541ac103e239ce63111607afe89ea6
BLAKE2b-256 528cbda4cc6d8f2e35e2ed0171369aaf1a7d977ca5fc3d5e0a5ed57ab63a5506

See more details on using hashes here.

File details

Details for the file oklab-0.1.1-py2.py3-none-any.whl.

File metadata

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

File hashes

Hashes for oklab-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 45d1e3a034406ba811a577709c4ce51a47b2eeb2614b5b1585267dc802dea582
MD5 c81965dc11e3f19ded4631764099657f
BLAKE2b-256 fef377a667af4ad73cb02d6fa3faa0bd0677579a2d1f120b449a23e3c2974841

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