Package: python-avatars
python_avatarsAvatar library in PythonTable of contentsFeaturesInstallUsageCreate your own avatarCreate a random avatarCustom shirt textExpand the libraryLicenseAcknowledgmentsFeaturesHighly customizable. Design your own clothes, hair styles, eyes... and add them to the library copying the svg files into a directoryVanilla Python. No external libraries neededThe library contains some colors for clothes, hair and skin and supports user defined colors using hex encodingPure SVGRandom avatar generationInstallUsing pip, from PyPi (latest stable release):pip install python-avatarsUsing pip, from this repository (May not be stable!):git clone https://github.com/ibonn/python_avatars.git python_avatars
cd python_avatars
pip install -e .UsageCreate your own avatarimportpython_avatarsaspamy_avatar=pa.Avatar(style=pa.AvatarStyle.CIRCLE,background_color=pa.BackgroundColor.BLACK,top=pa.HairType.STRAIGHT_2,eyebrows=pa.EyebrowType.DEFAULT_NATURAL,eyes=pa.EyeType.DEFAULT,nose=pa.NoseType.DEFAULT,mouth=pa.MouthType.EATING,facial_hair=pa.FacialHairType.NONE,# You can use hex colors on any color attribute...skin_color="#00FFFF",# Or you can use the colors provided by the libraryhair_color=pa.HairColor.BLACK,accessory=pa.AccessoryType.NONE,clothing=pa.ClothingType.HOODIE,clothing_color=pa.ClothingColor.HEATHER)# Save to a filemy_avatar.render("my_avatar.svg")Create a random avatarimportpython_avatarsaspa# Completely random avatarrandom_avatar_1=pa.Avatar.random()# Completely random avatar except for the hatrandom_avatar_2=pa.Avatar.random(top=pa.HatType.HAT)# More attributes can stay fixed# Fixed avatar but random clothesrandom_avatar_3=pa.Avatar(style=pa.AvatarStyle.CIRCLE,hair_color=pa.HairColor.BLACK,accessory=pa.AccessoryType.NONE,clothing=pa.ClothingType.pick_random(),# The clothes are chosen randomly)Custom shirt textWhen using the graphic shirt, -ClothingType.GRAPHIC- you can set a custom text if you want to.importpython_avatarsaspapa.Avatar(style=pa.AvatarStyle.CIRCLE,background_color='#FF00FF',# Choose graphic shirtclothing=pa.ClothingType.GRAPHIC_SHIRT,clothing_color=pa.ClothingColor.GRAY_02,# Important to choose this as shirt_graphic, otherwise shirt_text will be ignoredshirt_graphic=pa.ClothingGraphic.CUSTOM_TEXT,shirt_text='Chess').render("avatar_text.svg")will output the fileavatar_text.svg:Expand the librarySuppose you have a file calledsuit.svgthat looks like thisYou can add it to the library just by runningfrompython_avatarsimportinstall_part# Install the new partinstall_part("suit.svg",pa.ClothingType)And then use itsuit_avatar=pa.Avatar.random(clothing=pa.ClothingType.SUIT)suit_avatar.render("suit_avatar.svg")Which outputs the filesuit_avatar.svgthat looks like thisThe name of the newly added value will be exactly the name of the svg file converted to uppercase replacing all non alphanumeric chars with underscores and removing all leading digits.Uninstalling the installed part is as easy as installing itfrompython_avatarsimportuninstall_part,ClothingTypeuninstall_part(ClothingType.SUIT,confirm=False)# confirm=False will not prompt for confirmationLicenseThis project is licensed under the MIT License - see theLICENSE filefor detailsAcknowledgmentsAvatars designed byPablo Stanley(https://avataaars.com/)Additional avatar parts from blush.design, designed byPablo Stanley(https://blush.design/)