Skip to main content

Python port of d3-color

Project description

pyd3js-color

PyPI version Python versions License: ISC CI Security

Python port of d3-color.

Tracked version: see upstream_lock.json.

What is d3-color?

d3-color implements color manipulation and parsing for CSS-like strings (rgb, hsl, hex, named colors), plus conversions among RGB, HSL, Lab, HCL/LCH, and Cubehelix, including formatters (formatRgb, formatHex, formatHsl, …).

This package mirrors that API in Python so visualization code can share the same color semantics as D3 without a JavaScript runtime.

What you get

  • 100% upstream export parity (for the pinned d3-color@3.1.0): the compatibility matrix below lists every upstream export; none are marked [missing].
  • 100% Python test coverage for pyd3js_color (run the coverage command below).
  • Upstream d3-color JS tests vendored under packages/pyd3js-color/upstream/d3-color/test/; they are run via a pytest gate (-m upstream) after npm install in that directory.

Install

From PyPI:

pip install pyd3js-color

This repo is a uv workspace monorepo. For local development:

uv sync --group dev

Usage

import pyd3js_color as c

red = c.color("red")
print(red.formatRgb())
print(red.rgb().brighter(0.5).formatHex())

print(c.hsl(120, 0.5, 0.5).formatHsl())
print(c.lab(50, 10, -20).formatRgb())
print(c.cubehelix(300, 0.5, 0.5).formatRgb())
rgb(255, 0, 0)
#ff4040
hsl(120, 50%, 50%)
rgb(137, 117, 211)
rgb(142, 93, 166)

Stability & intentional deviations

  • Signed zero / JS float trivia: behavior matches D3 where tests require it; any residual float differences are covered in unit tests (oracle payloads stay JSON-safe).
  • Oracle parity limits: optional oracle tests compare JSON-safe strings and numbers only (NaN / -0 are exercised in Python tests instead).

Compatibility matrix

Pinned upstream inventory: docs/UPSTREAM_API.md (from d3-color@3.1.0).

Legend:

  • [oracle]: implemented with optional oracle parity for representative JSON-safe cases (string/numeric outputs).
  • [unit-only: …]: implemented; oracle coverage is limited by JSON or by API shape.
  • [missing]: reserved for upstream drift (should not appear for the pinned version).

Upstream exports (d3-color@3.1.0)

  • color — [oracle]
  • cubehelix — [oracle]
  • gray — [oracle]
  • hcl — [oracle]
  • hsl — [oracle]
  • lab — [oracle]
  • lch — [oracle]
  • rgb — [oracle]

Testing

Run the package tests:

uv run pytest packages/pyd3js-color/tests

Coverage (Python)

uv run pytest packages/pyd3js-color/tests --cov=pyd3js_color --cov-report=term-missing

Oracle parity tests (Node)

Some tests compare behavior against real d3 (includes d3-color) via the repo’s Node oracle:

cd tools/oracle && npm ci
uv run pytest -m oracle packages/pyd3js-color/tests

Notes:

  • Oracle tests must use JSON-safe values where practical (avoid ambiguous -0 / NaN in payloads).
  • You can optionally enable local oracle caching by creating packages/pyd3js-color/.env with:
    • ORACLE_CACHE=1 (do not commit it).

Upstream d3-color test suite (vendored)

We vendor the pinned upstream d3-color repo (including its Mocha test suite) and run it via pytest.

uv run python scripts/vendor_upstream.py
cd packages/pyd3js-color/upstream/d3-color && npm install --legacy-peer-deps
uv run pytest -m upstream packages/pyd3js-color/tests

Documentation

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

pyd3js_color-0.1.0.tar.gz (18.9 kB view details)

Uploaded Source

Built Distribution

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

pyd3js_color-0.1.0-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file pyd3js_color-0.1.0.tar.gz.

File metadata

  • Download URL: pyd3js_color-0.1.0.tar.gz
  • Upload date:
  • Size: 18.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.14

File hashes

Hashes for pyd3js_color-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e4e9fbab9988f79ec6d8e98f2d36862afe1332cd8bb17d2090a5fa65c59fdc2c
MD5 9a491461219c9bc6d386bf63c990ebb8
BLAKE2b-256 2ad63f6358c66d11c937819da62150e36afadff558c604ba7159f8f30069bb82

See more details on using hashes here.

File details

Details for the file pyd3js_color-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyd3js_color-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.14

File hashes

Hashes for pyd3js_color-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0b5ea49faaf8246e2e65b659cc582a1ececf651ca79c9a927c884557ef3e09c
MD5 4ee4e62e0b75abf4680977185e8af4dc
BLAKE2b-256 c4aa7686055db6cbc8b7792dafede2b3840b42be1b21716a563ca7f97d1077d5

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