Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to create your own Avatar using Python ?

  • Last Updated : 24 Feb, 2021

In this article, we will discuss how to create a custom avatar using Python. In order to perform this task. You don’t have to create it yourself on software or download it from some website, but a few lines of code will help you to generate an avatar of your choice.

We will be using the py-avataaars package from which we will be creating those beautiful avatars. The basic syntax of this module is:

from py_avataaars import PyAvataaar

avatar = PyAvataaar()

Here the PyAvataaar Class is in the which is responsible for a number of functionalities, out of which the major one is setting the parameters of the avatar for eg: change in skin color, outfit, eyes, hairs, hair colors, moods etc.

So, let’s begin…

Step 1: Installation of some packages. 

Step 2: Writing the python program.

  • First, we will try to generate the default avatar by writing this code and see if this works properly or not


# importing the require package
from py_avataaars import PyAvataaar  
# assigning various parameters to our avatar
avatar = PyAvataaar()
# rendering the avatar in png format


The above program will generate the AVATAR_1.png file in the folder where you’ve kept this python program. Once the above program is running properly, then we will generate the avatars according to our needs with this by using PyAvataaar() method.


PyAvataaar(style, skin_color, hair_color, facial_hair_type, top_type, mouth_type, eye_type, eyebrow_type, nose_type, accessories_type, clothe_type, clothe_graphic_type)



# Python program to create custom avatars
# importing the require package
import py_avataaars as pa  
# assigning various parameters to our avatar
avatar = pa.PyAvataaar(style=pa.AvatarStyle.CIRCLE,
# rendering the avatar in png format


You can always change the parameters of the avatar accordingly by pressing the Ctrl button and hovering over the py_avataaars line, which will turn it blue and then you can click on it to see file, where you can find all the parameters, each written in a different class.


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!