Github-like Userpic (Avatar) Generator
Oversimplified Github-like userpic (avatar) generator.
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")
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 |
|---|---|---|
| Small | Large | Seeded |
|---|---|---|
The images are generated by just examples.
License
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tiny_userpic-1.0.0.tar.gz | 8.6 kB | Without provenance | Details for tiny_userpic-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tiny_userpic-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for tiny_userpic-1.0.0-py3-none-any.whl |
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}
|
Security for tiny-userpic 1.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.