How can I get a reference to a module from within that module? Also, how can I get a reference to the package containing that module?
If you have a class in that module, then the __module__ property of the class is the module name of the class. Thus you can access the module via sys.modules[klass.__module__]. This is also works for functions.
How to get a reference to a module inside the module itself?