Map any value to a deterministic color
Project description
str2col
Deterministically map any value to a color.
from str2col import Str2Col, str2col
# one-off
str2col("hello") # "#41eaa0"
str2col("hello", fmt="rgb") # (65, 234, 160)
# reusable converter with constraints
conv = Str2Col(seed="myapp", hue_range=(180, 300), sat_range=(0.5, 0.8))
conv.to_hex("label A") # "#..."
conv.to_rgb("label A") # (R, G, B)
conv.to_hsl("label A") # (hue, sat, light)
conv.to_ansi_fg("label A") # "\033[38;2;...m"
conv.to_ansi_bg("label A") # "\033[48;2;...m"
Supported types: strings, ints, floats, None.
Install
pip install str2col
CLI
str2col hello
str2col hello --format rgb
str2col hello --format ansi_fg --text "hello world"
echo "hello" | str2col
Options:
| Flag | Default | Description |
|---|---|---|
--format / -f |
hex |
hex, rgb, rgb_float, hsl, ansi_fg, ansi_bg |
--seed |
none | shift the color mapping |
--hue-range MIN MAX |
0 360 |
restrict hue (degrees) |
--sat-range MIN MAX |
0.4 0.9 |
restrict saturation |
--light-range MIN MAX |
0.35 0.65 |
restrict lightness |
--text TEXT |
none | print TEXT in the computed color |
How it works
The input is coerced to a string and hashed with MD5. Three independent 4-byte chunks of the digest are mapped into the configured HSL ranges, then converted to the requested output format via Python's colorsys module.
Project details
Release history Release notifications | RSS feed
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 str2col-0.1.2.tar.gz.
File metadata
- Download URL: str2col-0.1.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e6a34e7e8581786e761d527a7008491da51327a11c180b3a289f394fda17370
|
|
| MD5 |
e89d98b69cb5b3676f5e4d0410a2f7c3
|
|
| BLAKE2b-256 |
c189cff0967d5af4504019d88879ee54f58ce62b1003fb0043d4448b3c03e698
|
Provenance
The following attestation bundles were made for str2col-0.1.2.tar.gz:
Publisher:
publish.yml on roncofaber/str2col
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
str2col-0.1.2.tar.gz -
Subject digest:
7e6a34e7e8581786e761d527a7008491da51327a11c180b3a289f394fda17370 - Sigstore transparency entry: 2188102627
- Sigstore integration time:
-
Permalink:
roncofaber/str2col@e2a61dbbda0f90ad9952d2a0f40c7ac0e4a5de1e -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/roncofaber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2a61dbbda0f90ad9952d2a0f40c7ac0e4a5de1e -
Trigger Event:
push
-
Statement type:
File details
Details for the file str2col-0.1.2-py3-none-any.whl.
File metadata
- Download URL: str2col-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcb93096a742cac368f5520cf12ae89dc06418431609e7e0869554a8facbdfb6
|
|
| MD5 |
58de5189dde8ef8e1c2019a0fd4e1ea7
|
|
| BLAKE2b-256 |
f7f40dbe7f65daa7e0a67efb36dc5dc2bf0de08c377ccde9e6af00c4a8b8c92d
|
Provenance
The following attestation bundles were made for str2col-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on roncofaber/str2col
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
str2col-0.1.2-py3-none-any.whl -
Subject digest:
fcb93096a742cac368f5520cf12ae89dc06418431609e7e0869554a8facbdfb6 - Sigstore transparency entry: 2188102630
- Sigstore integration time:
-
Permalink:
roncofaber/str2col@e2a61dbbda0f90ad9952d2a0f40c7ac0e4a5de1e -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/roncofaber
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2a61dbbda0f90ad9952d2a0f40c7ac0e4a5de1e -
Trigger Event:
push
-
Statement type: