Extract the rendered color palette from any website as a typed result.
Project description
colorsense
Extract the rendered color palette of any website as a structured, typed Python object.
colorsense renders a page in a headless browser, harvests its design tokens and computed element colors, and classifies them into a 60/30/10 palette — primary, secondary, accent, and neutrals, each with ranked, scored candidates. The result is a Pydantic model, ready for downstream consumers (including AI models) that need to understand a site's color identity.
Installation
pip install colorsense
playwright install chromium
Requires Python 3.12+. Rendering uses headless Chromium via Playwright;
the browser binary is not a pip dependency, so run playwright install chromium once after
installing (on Linux, also playwright install-deps chromium for the OS libraries).
Quick start
analyze is async — await it from an event loop, or wrap it with asyncio.run:
import asyncio
from colorsense import analyze, PaletteRole
result = asyncio.run(analyze("https://example.com"))
for theme, palette in result.themes.items():
candidates = palette.roles.mapping[PaletteRole.primary]
if candidates: # every role is present; empty tuple when none detected
best = candidates[0]
print(theme, best.color.hex, best.probability)
Each role — primary, secondary, accent, neutral_light, neutral_dark — maps to a
probability-ranked tuple of candidates; take [0] for the best pick. Inside an async
application (e.g. a FastAPI endpoint), just result = await analyze(url).
See the usage guide for the full result schema, options, and fetch policy.
Features
- 60/30/10 palette classification — five roles, each with ranked candidates carrying a
confidence (
probability) and page-area dominance (area). - Typed, serializable results —
analyzereturns a frozen PydanticAnalysisResult;result.model_dump_json()round-trips. - OKLCH out of the box — every
Colorcarries an sRGBhexplus cached OKLCH coordinates, so you can derive theme-matched tints, shades, and contrast without re-parsing hex strings. - Light and dark themes — opt into dark mode rendering; near-identical light/dark renders collapse to a single reported theme.
- Declared vs. rendered reconciliation — reports the site's CSS custom properties and discrepancies between what is declared and what is actually used.
- Status-color filtering — success/error/warning colors are detected and kept out of the palette, so an error banner never masquerades as a brand accent.
- Polite, controllable fetching — configurable User-Agent,
robots.txtgate withCrawl-delaysupport, per-host rate limiting, render caching, and a per-request egress filter. - Async-native and concurrent — themes render concurrently in one shared browser; CPU work is offloaded so the event loop stays responsive.
Security
colorsense fetches and fully renders third-party pages. If untrusted or user-supplied URLs
can reach analyze from a server, treat it as an SSRF surface: validate hosts before
calling, and use PolitenessPolicy(request_filter=...) to gate every request the rendered
page makes. The threat model and required controls are documented in
SECURITY.md — read it before exposing analyze to untrusted input.
Documentation
- Usage guide — options, the result schema, errors, and fetch policy.
- Advanced guide — design-token auditing and custom tuning.
- SECURITY.md — threat model and consumer responsibilities.
- CONTRIBUTING.md — development setup and contribution workflow.
- CHANGELOG.md — release history.
Support & license
Bug reports and feature requests: GitHub Issues. Licensed under the MIT License.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file colorsense-0.2.0.tar.gz.
File metadata
- Download URL: colorsense-0.2.0.tar.gz
- Upload date:
- Size: 129.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba48d5f86363a10b6fbddb1bb35c7382df7071d9a84a16950d615841dd97f3be
|
|
| MD5 |
a41d2062a8f604839cdec8a0dc073a3d
|
|
| BLAKE2b-256 |
8a4d6f1491ba74ae1e2f0e234a5346caf230aa7c991ab8124494ca0e0690b79f
|
Provenance
The following attestation bundles were made for colorsense-0.2.0.tar.gz:
Publisher:
publish.yml on cassidyhhaas/colorsense
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
colorsense-0.2.0.tar.gz -
Subject digest:
ba48d5f86363a10b6fbddb1bb35c7382df7071d9a84a16950d615841dd97f3be - Sigstore transparency entry: 1774430066
- Sigstore integration time:
-
Permalink:
cassidyhhaas/colorsense@ba801aec5c89f93f3d98c42531cbe8de10bbd8c5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/cassidyhhaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ba801aec5c89f93f3d98c42531cbe8de10bbd8c5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file colorsense-0.2.0-py3-none-any.whl.
File metadata
- Download URL: colorsense-0.2.0-py3-none-any.whl
- Upload date:
- Size: 76.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74c0657f38fe9f9ac88025987935753e882120fb81669d0ed264e4ab5f516db9
|
|
| MD5 |
b8e11db2e03e0c7fda65c6166903c5a5
|
|
| BLAKE2b-256 |
2390de4877970b1767ac892540243bfb394bfacc9132bd62b64678f8fbb3987c
|
Provenance
The following attestation bundles were made for colorsense-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on cassidyhhaas/colorsense
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
colorsense-0.2.0-py3-none-any.whl -
Subject digest:
74c0657f38fe9f9ac88025987935753e882120fb81669d0ed264e4ab5f516db9 - Sigstore transparency entry: 1774430322
- Sigstore integration time:
-
Permalink:
cassidyhhaas/colorsense@ba801aec5c89f93f3d98c42531cbe8de10bbd8c5 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/cassidyhhaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@ba801aec5c89f93f3d98c42531cbe8de10bbd8c5 -
Trigger Event:
release
-
Statement type: