Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

str2col-0.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

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

str2col-0.1.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

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

Hashes for str2col-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7e6a34e7e8581786e761d527a7008491da51327a11c180b3a289f394fda17370
MD5 e89d98b69cb5b3676f5e4d0410a2f7c3
BLAKE2b-256 c189cff0967d5af4504019d88879ee54f58ce62b1003fb0043d4448b3c03e698

See more details on using hashes here.

Provenance

The following attestation bundles were made for str2col-0.1.2.tar.gz:

Publisher: publish.yml on roncofaber/str2col

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for str2col-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fcb93096a742cac368f5520cf12ae89dc06418431609e7e0869554a8facbdfb6
MD5 58de5189dde8ef8e1c2019a0fd4e1ea7
BLAKE2b-256 f7f40dbe7f65daa7e0a67efb36dc5dc2bf0de08c377ccde9e6af00c4a8b8c92d

See more details on using hashes here.

Provenance

The following attestation bundles were made for str2col-0.1.2-py3-none-any.whl:

Publisher: publish.yml on roncofaber/str2col

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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