ui-avatars
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
avatar_url(name="Ada Lovelace", mask="hexagon")
# crop the image to a hexagon via wsrv.nl
avatar_url(name="Ada Lovelace", format="webp", proxy="images.example.com")
# use a self-hosted wsrv.nl instance instead of the public api
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
Metadata
Release files for ui-avatars 1.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ui_avatars-1.2.5.tar.gz | 6.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ui_avatars-1.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.8 kB
Release files / ui_avatars-1.2.5.tar.gz
| Download URL | ui_avatars-1.2.5.tar.gz |
|---|---|
| Size | 6.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d8fba5e167ccd5d6b532ecd7d232b90349112fd2673941c4806c7ee57e0774a
|
|
BLAKE2b-256 checksum How to use checksums |
a7d8edf6f2db4a8d590459b935ebbd81405784747429182b910ea67553ab3227
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency logRelease files / ui_avatars-1.2.5-py3-none-any.whl
| Download URL | ui_avatars-1.2.5-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
60f40a1dbad172a89199ef509cadfe4cb3d323ebbaa76bcb073ff199977f8a30
|
|
BLAKE2b-256 checksum How to use checksums |
00903fa24d7df3ee822bb87475a62062d6c9ed2a54e1fb96183eff27b253d45f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 2, 2026.
Transparency log