pyd3js-color
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-colorJS tests vendored underpackages/pyd3js-color/upstream/d3-color/test/; they are run via a pytest gate (-m upstream) afternpm installin 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/-0are 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/NaNin payloads). - You can optionally enable local oracle caching by creating
packages/pyd3js-color/.envwith: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
- Changelog:
docs/CHANGELOG.md - Upstream export inventory:
docs/UPSTREAM_API.md - Updating upstream:
docs/UPSTREAM_UPDATE.md
Metadata
Release files for pyd3js-color 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pyd3js_color-0.1.0.tar.gz | 18.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyd3js_color-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.5 kB
Release files / pyd3js_color-0.1.0.tar.gz
| Download URL | pyd3js_color-0.1.0.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4e9fbab9988f79ec6d8e98f2d36862afe1332cd8bb17d2090a5fa65c59fdc2c
|
|
BLAKE2b-256 checksum How to use checksums |
2ad63f6358c66d11c937819da62150e36afadff558c604ba7159f8f30069bb82
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.14
|
Release files / pyd3js_color-0.1.0-py3-none-any.whl
| Download URL | pyd3js_color-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b0b5ea49faaf8246e2e65b659cc582a1ececf651ca79c9a927c884557ef3e09c
|
|
BLAKE2b-256 checksum How to use checksums |
c4aa7686055db6cbc8b7792dafede2b3840b42be1b21716a563ca7f97d1077d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.11.14
|