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

Metadata

Release files for tiny-userpic 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tiny-userpic 1.0.0
File Size Uploaded
tiny_userpic-1.0.0.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tiny-userpic 1.0.0
File Interpreter ABI Platform
tiny_userpic-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 15.8 kB

Release files / tiny_userpic-1.0.0.tar.gz

Download URL tiny_userpic-1.0.0.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
de147d9ebcccad73c87715ab636edea7064bf0a20336d73f09c0feeb3d2bca17
BLAKE2b-256 checksum
How to use checksums
b73e98cbb8fc202bfc5d9f39c3eefb1d6eb64033b5f3b0b4e0debab277af43d9
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / tiny_userpic-1.0.0-py3-none-any.whl

Download URL tiny_userpic-1.0.0-py3-none-any.whl
Size 7.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00ed47964c7c0eddb32d5a2f17e028a8310c1c25d0fe1fe58b42d3b642f30bab
BLAKE2b-256 checksum
How to use checksums
4d4073c2476590d4719856e699415de6d58a368a2fecd915ea833c71371aeea3
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release 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