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 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 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 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.2.0.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.0-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: oklab-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 1ec11039e64d9c5e7d87c027506d972daa7ac4370260fd86e0a4993d180c8a48
MD5 10e5b6f3f1ea719e2f7f75865a605503
BLAKE2b-256 6b87744ad2fe7604ed14d8790390ad9b42f87d28fbee3e743d04b164d7b971b9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: oklab-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.4 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.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8bb13c9bc959d4bf69f965b695e8357ba0d57cb8f9eff5acd5b7862172e06f27
MD5 491a834b5205bb6822080f6744754867
BLAKE2b-256 6c0cc96a21b972e6d2c5d5370a21be26705e178c9919c1796507684313abef5c

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