Skip to main content

Map any value to a deterministic color

Project description

str2col

Map any value to a color. The same input always produces the same color.

from str2col import Str2Col, str2col

# one-off
str2col("hello")              # "#a3c9f1"
str2col("hello", fmt="rgb")   # (163, 201, 241)

# 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"

Any type works: strings, ints, floats, None.

Install

pip install str2col

No runtime dependencies.

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.1.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.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file str2col-0.1.1.tar.gz.

File metadata

  • Download URL: str2col-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 e2eb63225253e63ddb1bf4aa02b0260b6be06bbdaeae6d5f6d7634a471f48988
MD5 9bc9724ccff343e1d1535a22a652dfd2
BLAKE2b-256 c153e967badf7a6c70f77ddb2082ce039b24e4429282534f19c490e42ac442de

See more details on using hashes here.

Provenance

The following attestation bundles were made for str2col-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: str2col-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7eddeed431ff10d754da7ea8978d8f578c5d95aec7d526917b6f22b07ce06a4e
MD5 a6f7a1ca9ab234df1a2b5b7d633ce8b4
BLAKE2b-256 60008c5b7777137e14b7fa4a5026f700a7b8fad40efedd3975196459bb2bf29b

See more details on using hashes here.

Provenance

The following attestation bundles were made for str2col-0.1.1-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