Skip to main content

pyavatar

Create default user avatars from a given string

This package creates simple user avatars that can be used in web-applications.
Avatars are generated from the first letter of a given string input.

Installation

Pyavatar is on Pypi so all you need is:

pip install pyavatar

Usage

Generate an avatar

>>> from pyavatar import PyAvatar
>>>
>>> avatar = PyAvatar("smallwat3r", size=250)  # use a specific size
>>> avatar = PyAvatar("smallwat3r", capitalize=False)  # without capitalization
>>> avatar = PyAvatar("smallwat3r", color=(40, 176, 200))  # use a specific color
>>> avatar = PyAvatar("smallwat3r", fontpath="/Users/me/fonts/myfont.ttf")  # use a specific font

Change the avatar color

>>> avatar.color
(191, 91, 81)
>>> avatar.change_color()  # random color
>>> avatar.color
(203, 22, 126) 
>>> avatar.change_color("#28b0c8")  # using an hex color code
>>> avatar.color
'#28b0c8'

Save the avatar as a base64 image

>>> image = avatar.base64_image("jpeg")
'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBg ...'

You can then render it in an html tag with Jinja or another template engine

<img src="{{ image }}" alt="My avatar" />

Or save it as a bytes array

>>> avatar.stream("png")
b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\xfa\x00\x00 ...'

Or save it as a file locally

>>> import os
>>> avatar.save(f"{os.getcwd()}/me.png")

Development

Requirements

Make sure you're using a version of Python >= 3.10

  • Create a virtual environment and install the dependencies
    make venv deps
    

Sanity checks

  • Unit tests

    make tests
    
  • Mypy

    make mypy
    
  • Ruff

    make ruff
    
  • Run all the above

    make ci
    

Code formatting

We're using YAPF to format the code

make yapf

Release to Pypi

make release

Release files for pyavatar 0.1.8

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

Source distribution (sdist)

Source distribution for pyavatar 0.1.8
File Size Uploaded
pyavatar-0.1.8.tar.gz 73.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyavatar 0.1.8
File Interpreter ABI Platform
pyavatar-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size:144.0 kB

Release files / pyavatar-0.1.8.tar.gz

Download URL pyavatar-0.1.8.tar.gz
Size 73.4 kB
Tags Source
SHA-256 checksum
How to use checksums
061df5eba2e71e2c6a6d2dbb0d7229ae46b16b79c8c8fa9ee7ef7badf776c625
BLAKE2b-256 checksum
How to use checksums
3f69eee3ceb12a7c879a881db621977da467fe71539a87536b1bdef9398e777f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release files / pyavatar-0.1.8-py3-none-any.whl

Download URL pyavatar-0.1.8-py3-none-any.whl
Size 70.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32c4a0e54e7229eec96f118e61cd84f5698510c7df3b475b1f42e9c57328f9d1
BLAKE2b-256 checksum
How to use checksums
eed3f5ca03e1fdcbad555b986c2fbdcac6799f32a826a67adac4de564307ac5c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.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