Skip to main content

Github-like Userpic (Avatar) Generator

Oversimplified Github-like userpic (avatar) generator.

Ruff PyPI PyPI

Turns any text — an email, a username, a UUID — into a symmetric identicon-style avatar, rendered as a PIL image or an SVG string. The same input always produces the same picture. The only dependency is Pillow.

Installation

pip install tiny-userpic

Requires Python 3.10 or newer. The package installs a single top-level module named userpic.

Quickstart

from userpic import make_userpic_image_from_string

make_userpic_image_from_string(text="user@example.com").save("avatar.png")
avatar.png

API

Four functions share the same parameters and differ only in the output format and in where the pattern comes from:

returns pattern comes from
make_userpic_image PIL.Image seed or system entropy
make_userpic_svg str (SVG) seed or system entropy
make_userpic_image_from_string PIL.Image text
make_userpic_svg_from_string str (SVG) text

Images

from userpic import make_userpic_image

# a new random avatar on every call
make_userpic_image(size=(7, 5)).save("random.png")

# the same integer seed always gives the same avatar
make_userpic_image(size=(7, 5), seed=42).save("seeded.png")

# transparency: RGBA mode plus a fully transparent background
make_userpic_image(
    size=(7, 5),
    mode="RGBA",
    background=(255, 255, 255, 0),
    foreground=(0, 0, 128, 255),
).save("transparent.png")

SVG

from userpic import make_userpic_svg, make_userpic_svg_from_string

svg = make_userpic_svg_from_string(text="user@example.com", size=(7, 5))
with open("avatar.svg", "w") as file:
    file.write(svg)

# seeded, without the background rectangle
svg = make_userpic_svg(size=(7, 5), background=None, seed=42)

Parameters

name default description
text input string for the *_from_string functions
size (5, 5) pattern size in cells as (width, height); the width must be at least 2
image_size (300, 300) output size in pixels
padding (20, 20) blank border around the pattern, in pixels
background "white" color name, hex string or RGB/RGBA tuple; None omits the background rectangle in SVG
foreground "black" same formats as background
mode "RGB" PIL image mode, image functions only; use "RGBA" for transparency
seed None any integer for reproducible output; omit for a random avatar

The pattern has to fit into the image: image_size minus twice the padding must leave at least one pixel per cell, otherwise a ValueError is raised.

Examples

Basic Colored Transparent
basic colored transparent
Small Large Seeded
small large seeded

The images are generated by just examples.

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

tiny_userpic-1.0.0.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

tiny_userpic-1.0.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file tiny_userpic-1.0.0.tar.gz.

File metadata

  • Download URL: tiny_userpic-1.0.0.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tiny_userpic-1.0.0.tar.gz
Algorithm Hash digest
SHA256 de147d9ebcccad73c87715ab636edea7064bf0a20336d73f09c0feeb3d2bca17
MD5 4d78fbc0f9333f1965a7e45e73559adb
BLAKE2b-256 b73e98cbb8fc202bfc5d9f39c3eefb1d6eb64033b5f3b0b4e0debab277af43d9

See more details on using hashes here.

File details

Details for the file tiny_userpic-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: tiny_userpic-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tiny_userpic-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00ed47964c7c0eddb32d5a2f17e028a8310c1c25d0fe1fe58b42d3b642f30bab
MD5 3fe56f9eaf9cd3767a72c47ea15651c8
BLAKE2b-256 4d4073c2476590d4719856e699415de6d58a368a2fecd915ea833c71371aeea3

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.4.0

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

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