class _MyClass(object):

    def foo(self):
        print('foo()')
_MyClass.instance = _MyClass()
import sys
_ref = sys.modules[__name__]
sys.modules[__name__] = _MyClass.instance
When to use a Singleton in python?