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
  • 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

oklab-0.1.0-py2.py3-none-any.whl (5.7 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: oklab-0.1.0-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.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 4af3b7c2194646b526ba1ae6427f0582b6c7b19222770577a057d3acf92cd331
MD5 f875fb3ba625a0ff03188fee150f4a59
BLAKE2b-256 1df33cbeef1753cd0d8160619f47ea3839d5a51bb2e07f3ef1166fa519ff5035

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