First, it seems proper to me to state that I've read over the following questions:
And, I don't feel like they address my use case. That said, here's my question:
How can I dynamically import from a configuration file like this:
[imports]
/var/imports/foo.py = baz monkey
/var/imports/bar.py = ape
So that I can call the known objects via RESTful interface like this.
# http://localhost/data?operation=get&class=baz&id=1
def handler(object):
def handle(self):
cls = instantiate(request.args["class"])
meth = request.args["operation"]
return getattr(cls,meth,request.args)
And it could respond with the result of get() on an instance of that class.
Here's a rough sketch of a class registry you could use like this:
Read your config file and invoke
add_file_classes
like this:then later:
Note that we aren't actually importing the files, simply executing them and collecting their results.