Create singleton from class

def singleton(klass):
    """
    Create singleton from class
    """
    instances = {}

    def getinstance(*args, **kwargs):
        if klass not in instances:
            instances[klass] = klass(*args, **kwargs)
        return instances[klass]
    return wraps(klass)(getinstance)