Singleton method for Redis connection in Python
The Singleton pattern is a way to work around the absence of global variables in Java. But Python has global variables, and it's usually possible to write shorter and simpler initialization code if you use them, for example:

import os

from redis import StrictRedis

_connection = None

def connection():
    """Return the Redis connection to the URL given by the environment
    variable REDIS_URL, creating it if necessary.

    """
    global _connection
    if _connection is None:
        _connection = StrictRedis.from_url(os.environ['REDIS_URL'])
    return _connection


Alternatively, you could memoize the function, for example using functools.lru_cache:

from functools import lru_cache
import os

from redis import StrictRedis

@lru_cache(maxsize=1)
def connection():
    """Return the Redis connection to the URL given by the environment
    variable REDIS_URL, creating it if necessary.

    """
    return StrictRedis.from_url(os.environ['REDIS_URL'])