Last Updated: February 25, 2016
· bt3gl

Using Gravatar in an App (Python)

Gravatar associates avatar images with email addresses. Users create an
account at and then upload their images.

To generate the avatar URL for a given email address, its MD5 hash is calculated:

>>> import hashlib
>>> hashlib.md5(''.encode('utf-8')).hexdigest()

The avatar URLs are then generated by appending the MD5 hash to URL http:// or

For example, you can type in your browser’s address bar to get the avatar image for the email address , or a default generated image if that email address does not have an
avatar registered.

So, for example, in your Python application, you can have the following code:

def gravatar(self, size=100, default='identicon', rating='g'):
    if request.is_secure:
        url = ''
        url = ''
    hash = hashlib.md5('utf-8')).hexdigest()
    return '{url}/{hash}?s={size}&d={default}&r={rating}'.format(url=url, hash=hash, size=size, default=default, rating=rating)