Skip to main content

A python API wrapper for DiceBear's avatar generating API.

Project description

DiceBear Py Wrapper

Downloads Downloads
dicebear is an API wrapper for https://dicebear.com. Using this wrapper you can get custom avatars for your program.
For an example go to examples/dicebear.py.


Useful links


How to install

Run pip install dicebear
If that doesn't work try py -m pip install dicebear


Usage

Important note: Pillow is not a required dependency, it's only required when you want to be able to edit the avatar images (using DAvatar.pillow()). When using a PIL function while it's not installed it will raise dicebear.errors.PILError.

from dicebear import DAvatar, DStyle, DOptions, DColor
from PIL import Image

options = DOptions(
    backgroundColor=DColor("#00ddd0"),
    rotate=90
)

av = DAvatar(
    style=DStyle.pixel_art,
    seed="John Apple",
    options=options
)

print(av.url_svg)

av.edit(
    extra_options=DOptions(
        backgroundColor=DColor("#000000")
    )
)
# This will keep the `rotate` option but override the `backgroundColor` option

print(av.url_png)

av.edit_specific(
    blank_options={
        "face": "variant04"
    }
)
# This edits the style specific options

print(av.url_png)

image: Image.Image = av.pillow()
# converts the DAvatar into a Pillow Image object

CLI Usage

Since version 0.4.0 there's a CLI for DiceBear. It can quickly create one or more avatars at a time but it can't take options.

To use the CLI go to https://github.com/jvherck/dicebear-cli and use pip install dicebear-cli to install the CLI


Customisation

Customise your avatars with these possibilities.

Styles

All the possible avatar styles.
https://avatars.dicebear.com/styles

  • adventurer
  • adventurer-neutral
  • avataaars
  • big-ears
  • big-ears-neutral
  • big-smile
  • bottts
  • croodles
  • croodles-neutral
  • identicon
  • initials
  • micah
  • miniavs
  • open-peeps
  • personas
  • pixel-art
  • pixel-art-neutral

Base Options

All the possible options for the avatar. These options work for all the styles.

  • seed (type: str) - the seed for the avatar generator, determine its basic looks
  • dataUri (type: bool) - whether to give the dataUri (default False)
  • flip (type: bool) - flips the image vertically (default False)
  • rotate (type: int) - rotates the avatar (default 0, min 0, max 360)
  • scale (type: int) - the scale of the avatar drawing itself (default 100, min 0, max 200)
  • radius (type: int) - the radius of the avatar (default 0, min 0, max 50)
  • size (type: int) - the size of the avatar (px) (default 256, min 1, max 256)
  • backgroundColor (type: DColor( " #ffffff " ) ) - the background color of the avatar (default white)
  • translateX (type: int) - move the avatar horizontally (default 0, min -100, max 100)
  • translateY (type: int) - move the avatar vertically (default 0, min -100, max 100)

Specific Style Options

Specific options to get a more detailed avatar. This is different for every style.
Click the style to see its options.

Formats

These are the only supported formats.
If you have Pillow (PIL) installed you can convert DAvatar to a PIL.Image.Image object to get a wider range of formats (Pillow doesn't support svg).

  • DFormat.png
  • DFormat.svg

Contributing

Currently not possible yet. However you do can open an issue to report a bug or error and I'll take a look at it.


Credits

Special thanks to DiceBear (Florian Körner) for making this amazing API and to all artists that helped making avatars!

Licenses and privacy policy

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dicebear-1.0.2.tar.gz (13.6 kB view hashes)

Uploaded Source

Built Distribution

dicebear-1.0.2-py3-none-any.whl (13.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page