Skip to main content

ui-avatars

PyPI CI Coverage Downloads License

Deterministic avatar URLs for light and dark designs: Gravatar or Libravatar photos falling back to colored initials via ui-avatars.com. Same input, same URL, always.

Install

pip install ui-avatars

Usage

from ui_avatars import avatar_url

avatar_url(name="Ada Lovelace", email="ada@example.com")
# Gravatar photo, falling back to generated initials

avatar_url(name="Ada Lovelace")
# straight ui-avatars.com URL, no Gravatar lookup

avatar_url(email="ada@example.com")
# initials from the first two letters of the email

avatar_url(name="Ada Lovelace", alpha=0.75, size=256, rounded=True)
# alpha, size, and ui-avatars.com rendering options as one-off overrides

avatar_url(name="Ada Lovelace", color="#dc2626")
# pick a specific color, skipping the palette

avatar_url(name="Ada Lovelace", alpha=1, background="#000")
# pin the background, let the text color rotate with the palette

avatar_url(name="Ada Lovelace", font_color="#fff")
# pin the text color, let the background rotate with the palette

avatar_url(name="Ada Lovelace", email="ada@example.com", format="png")
# force png or svg, note Gravatar errors for svg default images

avatar_url(name="Ada Lovelace", email="ada@example.com", source="libravatar")
# look up the photo on Libravatar instead of Gravatar

avatar_url(name="Ada Lovelace", email="ada@example.com", source="secure.gravatar.com")
# use a custom Gravatar-compatible photo source

avatar_url(name="Ada Lovelace", region="eu")
# use the EU ui-avatars.com endpoint for generated initials

avatar_url(name="Ada Lovelace", host="avatars.example.com")
# use a custom or self-hosted UI Avatars endpoint

Configuration

Reconfigure the shared avatars instance once, at startup, to change the palette for every call:

from ui_avatars import avatars

avatars.configure(colors=["#1d4ed8", "#b91c1c"], size=256, rounded=True)

Or build your own instance instead:

from ui_avatars import Avatars

avatars = Avatars(colors=["#1d4ed8", "#b91c1c"], size=256)
avatars.build(name="Ada Lovelace", email="ada@example.com")

The default palette is tailwind_colors's RAINBOW_500. You can swap the whole palette like so:

from tailwind_colors import TCH

avatars.configure(colors=TCH.RAINBOW_300)

For an independent background/text color instead of one tinted from the other, use a (background, text) tuple as a colors entry — alpha still applies to whichever background results:

avatars.configure(colors=[("#fee2e2", "#ef4444"), ("#ffedd5", "#f97316")])

Development

poetry install
poetry run pytest
poetry run ruff check .

License

MIT

Download files

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

Source Distribution

ui_avatars-1.2.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

ui_avatars-1.2.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file ui_avatars-1.2.3.tar.gz.

File metadata

  • Download URL: ui_avatars-1.2.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ui_avatars-1.2.3.tar.gz
Algorithm Hash digest
SHA256 f46323371fe09cfa79994ff6390a63f9c6189dc42363b3615806fb6d07f78453
MD5 b3ecfc8715246a9db5ebd52e6623abed
BLAKE2b-256 10f4b0dda7a8d4f8cf9e5dcfbb7b765898a03c1dc1059904872b1c2008f90e36

See more details on using hashes here.

Provenance

The following attestation bundles were made for ui_avatars-1.2.3.tar.gz:

Publisher: release.yml on stevelacey/ui-avatars-python

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

File details

Details for the file ui_avatars-1.2.3-py3-none-any.whl.

File metadata

  • Download URL: ui_avatars-1.2.3-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for ui_avatars-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a60baa6f49326ff433055939b0f17bed8e5051640c9b0f068d5ce05660a41f07
MD5 1efa9c9769d3aba668b997cc1cfcff65
BLAKE2b-256 da753196bd2ff40788c772a4f3e6f51ebc04ccaa9fd47fb8612a06ee01957c82

See more details on using hashes here.

Provenance

The following attestation bundles were made for ui_avatars-1.2.3-py3-none-any.whl:

Publisher: release.yml on stevelacey/ui-avatars-python

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

Release history Release notifications | RSS feed

This release

1.2.3 This release

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page