code: def singleton(klass):
      
      instances = {}
  
      def getinstance(*args, **kwargs):
          if klass not in instances:
              instances[klass] = klass(*args, **kwargs)
          return instances[klass]
      return wraps(klass)(getinstance)
docs: Create singleton from class