python-avatars


Namepython-avatars JSON
Version 1.4.1 PyPI version JSON
download
home_pagehttps://github.com/ibonn/python_avatars
SummarySVG avatar library for Python
upload_time2024-07-14 09:54:36
maintainerNone
docs_urlNone
authorIbon
requires_pythonNone
licenseMIT
keywords avatar svg python face custom
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # python_avatars

[![Codacy Badge](https://app.codacy.com/project/badge/Grade/0f0ba4f148724111a40681296d0dc740)](https://www.codacy.com/gh/ibonn/python_avatars/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ibonn/python_avatars&utm_campaign=Badge_Grade) ![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/ibonn/python_avatars) [![PyPi version](https://img.shields.io/pypi/v/python_avatars)](https://img.shields.io/pypi/v/python_avatars) ![PyPI - Downloads](https://img.shields.io/pypi/dm/python_avatars) ![GitHub top language](https://img.shields.io/github/languages/top/ibonn/python_avatars) 

[![Randomly generated avatars. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/random_gif_apng/avatars.png)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/random_gif_apng/avatars.png)](https://github.com/ibonn/python_avatars/blob/main/examples/random_gif_apng/avatars.png)

> Avatar library in Python

## Table of contents
1. [Features](#features)
2. [Install](#install)
3. [Usage](#usage)
    * [Create your own avatar](#create-your-own-avatar)
    * [Create a random avatar](#create-a-random-avatar)
    * [Custom shirt text](#custom-shirt-text)
    * [Expand the library](#expand-the-library)
4. [License](#license)
5. [Acknowledgments](#acknowledgments)

## Features
* Highly customizable. Design your own clothes, hair styles, eyes... and add them to the library copying the svg files into a directory
* Vanilla Python. No external libraries needed
* The library contains some colors for clothes, hair and skin and supports user defined colors using hex encoding
* Pure SVG
* Random avatar generation


## Install
Using pip, from PyPi (latest stable release):

    pip install python-avatars

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

## Usage
### Create your own avatar
```python
import python_avatars as pa

my_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 library
    hair_color=pa.HairColor.BLACK,
    accessory=pa.AccessoryType.NONE,
    clothing=pa.ClothingType.HOODIE,
    clothing_color=pa.ClothingColor.HEATHER
)

# Save to a file
my_avatar.render("my_avatar.svg")
```
### Create a random avatar
```python
import python_avatars as pa

# Completely random avatar
random_avatar_1 = pa.Avatar.random()

# Completely random avatar except for the hat
random_avatar_2 = pa.Avatar.random(top=pa.HatType.HAT)  # More attributes can stay fixed

# Fixed avatar but random clothes
random_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 text
When using the graphic shirt, - _ClothingType.GRAPHIC_ - you can set a custom text if you want to.

```python
import python_avatars as pa

pa.Avatar(
    style=pa.AvatarStyle.CIRCLE,
    background_color='#FF00FF',
    # Choose graphic shirt
    clothing=pa.ClothingType.GRAPHIC_SHIRT,
    clothing_color=pa.ClothingColor.GRAY_02,
    # Important to choose this as shirt_graphic, otherwise shirt_text will be ignored
    shirt_graphic=pa.ClothingGraphic.CUSTOM_TEXT,
    shirt_text='Chess'
).render("avatar_text.svg")
```
will output the file _avatar\_text.svg_:

[![Avatar wearing shirt with custom text. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/shirt_text/avatar_text.svg)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/shirt_text/avatar_text.svg)](https://github.com/ibonn/python_avatars/blob/main/examples/shirt_text/avatar_text.svg)

### Expand the library
Suppose you have a file called _suit.svg_
that looks like this

[![Suit ready to be used by the avatar. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/install/suit.svg)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/install/suit.svg)](https://github.com/ibonn/python_avatars/blob/main/examples/install/suit.svg)

You can add it to the library just by running
```python
from python_avatars import install_part

# Install the new part
install_part("suit.svg", pa.ClothingType)
```
And then use it
```python
suit_avatar = pa.Avatar.random(
    clothing=pa.ClothingType.SUIT
)

suit_avatar.render("suit_avatar.svg")
```
Which outputs the file _suit\_avatar.svg_ that looks like this

[![Randomly generated avatar wearing the installed suit. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/install/avatar_suit.svg)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/install/avatar_suit.svg)](https://github.com/ibonn/python_avatars/blob/main/examples/install/avatar_suit.svg)

The 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 it
```python
from python_avatars import uninstall_part, ClothingType

uninstall_part(ClothingType.SUIT, confirm=False)    # confirm=False will not prompt for confirmation
```

## License
This project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details

## Acknowledgments
* Avatars designed by [Pablo Stanley](https://twitter.com/pablostanley) ([https://avataaars.com/](https://avataaars.com/))
* Additional avatar parts from blush.design, designed by [Pablo Stanley](https://twitter.com/pablostanley) ([https://blush.design/](https://blush.design/collections/rChdrB8vX8xQJunpDPp8/avatars/avataaar-default))

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ibonn/python_avatars",
    "name": "python-avatars",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "avatar, svg, python, face, custom",
    "author": "Ibon",
    "author_email": "ibonescartin@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c2/b6/cca0fe90db8dd804a81dc1e428f40e168ac194d9a14d2b5268cdc45ef5d4/python_avatars-1.4.1.tar.gz",
    "platform": null,
    "description": "# python_avatars\n\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/0f0ba4f148724111a40681296d0dc740)](https://www.codacy.com/gh/ibonn/python_avatars/dashboard?utm_source=github.com&utm_medium=referral&utm_content=ibonn/python_avatars&utm_campaign=Badge_Grade) ![Code Climate maintainability](https://img.shields.io/codeclimate/maintainability/ibonn/python_avatars) [![PyPi version](https://img.shields.io/pypi/v/python_avatars)](https://img.shields.io/pypi/v/python_avatars) ![PyPI - Downloads](https://img.shields.io/pypi/dm/python_avatars) ![GitHub top language](https://img.shields.io/github/languages/top/ibonn/python_avatars) \n\n[![Randomly generated avatars. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/random_gif_apng/avatars.png)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/random_gif_apng/avatars.png)](https://github.com/ibonn/python_avatars/blob/main/examples/random_gif_apng/avatars.png)\n\n> Avatar library in Python\n\n## Table of contents\n1. [Features](#features)\n2. [Install](#install)\n3. [Usage](#usage)\n    * [Create your own avatar](#create-your-own-avatar)\n    * [Create a random avatar](#create-a-random-avatar)\n    * [Custom shirt text](#custom-shirt-text)\n    * [Expand the library](#expand-the-library)\n4. [License](#license)\n5. [Acknowledgments](#acknowledgments)\n\n## Features\n* Highly customizable. Design your own clothes, hair styles, eyes... and add them to the library copying the svg files into a directory\n* Vanilla Python. No external libraries needed\n* The library contains some colors for clothes, hair and skin and supports user defined colors using hex encoding\n* Pure SVG\n* Random avatar generation\n\n\n## Install\nUsing pip, from PyPi (latest stable release):\n\n    pip install python-avatars\n\nUsing pip, from this repository (May not be stable!):\n\n    git clone https://github.com/ibonn/python_avatars.git python_avatars\n    cd python_avatars\n    pip install -e .\n\n## Usage\n### Create your own avatar\n```python\nimport python_avatars as pa\n\nmy_avatar = pa.Avatar(\n    style=pa.AvatarStyle.CIRCLE,\n    background_color=pa.BackgroundColor.BLACK,\n    top=pa.HairType.STRAIGHT_2,\n    eyebrows=pa.EyebrowType.DEFAULT_NATURAL,\n    eyes=pa.EyeType.DEFAULT,\n    nose=pa.NoseType.DEFAULT,\n    mouth=pa.MouthType.EATING,\n    facial_hair=pa.FacialHairType.NONE,\n    # You can use hex colors on any color attribute...\n    skin_color=\"#00FFFF\",\n    # Or you can use the colors provided by the library\n    hair_color=pa.HairColor.BLACK,\n    accessory=pa.AccessoryType.NONE,\n    clothing=pa.ClothingType.HOODIE,\n    clothing_color=pa.ClothingColor.HEATHER\n)\n\n# Save to a file\nmy_avatar.render(\"my_avatar.svg\")\n```\n### Create a random avatar\n```python\nimport python_avatars as pa\n\n# Completely random avatar\nrandom_avatar_1 = pa.Avatar.random()\n\n# Completely random avatar except for the hat\nrandom_avatar_2 = pa.Avatar.random(top=pa.HatType.HAT)  # More attributes can stay fixed\n\n# Fixed avatar but random clothes\nrandom_avatar_3 = pa.Avatar(\n    style=pa.AvatarStyle.CIRCLE,\n    hair_color=pa.HairColor.BLACK,\n    accessory=pa.AccessoryType.NONE,\n    clothing=pa.ClothingType.pick_random(), # The clothes are chosen randomly\n)\n```\n\n### Custom shirt text\nWhen using the graphic shirt, - _ClothingType.GRAPHIC_ - you can set a custom text if you want to.\n\n```python\nimport python_avatars as pa\n\npa.Avatar(\n    style=pa.AvatarStyle.CIRCLE,\n    background_color='#FF00FF',\n    # Choose graphic shirt\n    clothing=pa.ClothingType.GRAPHIC_SHIRT,\n    clothing_color=pa.ClothingColor.GRAY_02,\n    # Important to choose this as shirt_graphic, otherwise shirt_text will be ignored\n    shirt_graphic=pa.ClothingGraphic.CUSTOM_TEXT,\n    shirt_text='Chess'\n).render(\"avatar_text.svg\")\n```\nwill output the file _avatar\\_text.svg_:\n\n[![Avatar wearing shirt with custom text. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/shirt_text/avatar_text.svg)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/shirt_text/avatar_text.svg)](https://github.com/ibonn/python_avatars/blob/main/examples/shirt_text/avatar_text.svg)\n\n### Expand the library\nSuppose you have a file called _suit.svg_\nthat looks like this\n\n[![Suit ready to be used by the avatar. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/install/suit.svg)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/install/suit.svg)](https://github.com/ibonn/python_avatars/blob/main/examples/install/suit.svg)\n\nYou can add it to the library just by running\n```python\nfrom python_avatars import install_part\n\n# Install the new part\ninstall_part(\"suit.svg\", pa.ClothingType)\n```\nAnd then use it\n```python\nsuit_avatar = pa.Avatar.random(\n    clothing=pa.ClothingType.SUIT\n)\n\nsuit_avatar.render(\"suit_avatar.svg\")\n```\nWhich outputs the file _suit\\_avatar.svg_ that looks like this\n\n[![Randomly generated avatar wearing the installed suit. (View at: https://github.com/ibonn/python_avatars/blob/main/examples/install/avatar_suit.svg)](https://raw.githubusercontent.com/ibonn/python_avatars/main/examples/install/avatar_suit.svg)](https://github.com/ibonn/python_avatars/blob/main/examples/install/avatar_suit.svg)\n\nThe 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.\n\nUninstalling the installed part is as easy as installing it\n```python\nfrom python_avatars import uninstall_part, ClothingType\n\nuninstall_part(ClothingType.SUIT, confirm=False)    # confirm=False will not prompt for confirmation\n```\n\n## License\nThis project is licensed under the MIT License - see the [LICENSE file](LICENSE) for details\n\n## Acknowledgments\n* Avatars designed by [Pablo Stanley](https://twitter.com/pablostanley) ([https://avataaars.com/](https://avataaars.com/))\n* Additional avatar parts from blush.design, designed by [Pablo Stanley](https://twitter.com/pablostanley) ([https://blush.design/](https://blush.design/collections/rChdrB8vX8xQJunpDPp8/avatars/avataaar-default))\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "SVG avatar library for Python",
    "version": "1.4.1",
    "project_urls": {
        "Documentation": "https://readthedocs.org/projects/python_avatars/",
        "Download": "https://pypi.org/project/python_avatars/",
        "Homepage": "https://github.com/ibonn/python_avatars",
        "Source Code": "https://github.com/ibonn/python_avatars"
    },
    "split_keywords": [
        "avatar",
        " svg",
        " python",
        " face",
        " custom"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b050a6c79dd2e1b9de1aa64f3b38e10be972308dd004f94ac76f6ea6060c9fd5",
                "md5": "0022af0a93aa7024f65b73f9be3c8a60",
                "sha256": "ef97b1f8ac23583367705f876fbbac1cc118435982532d882ccc788e95663722"
            },
            "downloads": -1,
            "filename": "python_avatars-1.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0022af0a93aa7024f65b73f9be3c8a60",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 301092,
            "upload_time": "2024-07-14T09:54:34",
            "upload_time_iso_8601": "2024-07-14T09:54:34.629353Z",
            "url": "https://files.pythonhosted.org/packages/b0/50/a6c79dd2e1b9de1aa64f3b38e10be972308dd004f94ac76f6ea6060c9fd5/python_avatars-1.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2b6cca0fe90db8dd804a81dc1e428f40e168ac194d9a14d2b5268cdc45ef5d4",
                "md5": "d00a674684b051dab3b31e2354a1a536",
                "sha256": "133dc0e1dfd778f0287aa6b6697da2677aeb3ce985ebf908205068e963165b0e"
            },
            "downloads": -1,
            "filename": "python_avatars-1.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "d00a674684b051dab3b31e2354a1a536",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 215434,
            "upload_time": "2024-07-14T09:54:36",
            "upload_time_iso_8601": "2024-07-14T09:54:36.542193Z",
            "url": "https://files.pythonhosted.org/packages/c2/b6/cca0fe90db8dd804a81dc1e428f40e168ac194d9a14d2b5268cdc45ef5d4/python_avatars-1.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-14 09:54:36",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ibonn",
    "github_project": "python_avatars",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "lcname": "python-avatars"
}
        
Elapsed time: 0.43692s