This is how you can think of packages and modules, but it is not necessary that the package / module be a directory / file in the file system.
You can save the package / module in a zip file and download it using zipimport.
You can load the module from a string variable:
import imp
code = """
def test():
print "function inside module!"
"""
name = "mymodule"
mymodule = imp.new_module(name)
exec code in mymodule.__dict__
>>> mymodule.test()
function inside module!
source
share