Support for federated avatars using pyLibravatar

Issue #1 new
Francois Marier
created an issue

Here's a suggestion to extend your Libravatar backend and easily add support for avatars hosted on domains other than

You can make use of the pyLibravatar module:

All you need to do to generate avatar URLs is this:

avatar_url = libravatar_url(email = '', https = 1)

Comments (6)

  1. Michael Bayer repo owner

    correct me if I'm wrong but looking at the source at it appears that each call to libravatar_url(), for which a naive implementation on our end would be called hundreds of times server side for some listings, performs a brand new DNS lookup ? this seems wasteful when some simple caching would eliminate lots of python/system/network calls.

    also is "_avatars._tcp.<domain>" some kind of standard or is this specific to pylibravatar ?

  2. Michael Bayer repo owner

    libravatar could allow for stateful usage pretty easily by basing it's API around a contextual object, like:

    ctx = pylibravatar.Context(cache=True)
    avatar_url = ctx.url("", https=True)

    where above ctx.url() would load the avatar from a local dictionary if already present - or better yet an LRU cache with a configurable size and an expiration time).

    the "ctx" here could at least hang around for the lifespan of a whole request, or be held persistently across requests.

  3. Francois Marier reporter

    That context object is a good idea.

    The thing about DNS though is that it's the world's largest caching system. I'm not sure I can do a better job than it does given that caching is built into all DNS resolution. After all, cache invalidation is one of the hardest problems in computer science :)

    You might be right that it would be worth adding another layer of caching on top, but I would be inclined to see if it's actually a problem before implementing something like this.

  4. Michael Bayer repo owner

    do 100 libravatar lookups and run it under cProfile, then compare to pulling the values out of a Python dictionary. My guess is you'll see a callcount difference well over two orders of magnitude.

  5. Log in to comment