I'm working with an API which has many sub components. I'm making a toolkit to interact with this API and I would like to make it so that I can dynamically load some of the classes based on variables, for example, loading all classes which have a variable api_module = True set inside.
.
├── APIModules
│ ├── ccu.py
│ ├── __init__.py
│ └── OpenAPI.py
The CCU class within the ccu file
class CCU:
api_module = True
actions = ['post_new_purge','get_purge_queue','get_purge_status']
This will help me to dynamically document and grow the toolkit as more classes are added without having to maintain lists of imports each time a new sub component is added. Is there an easy way to do this?
I know I can get a list of all the python files in the APIModules directory with a glob, but I then want to load and check any classes within the files without knowing what they might be called.
import os
import glob
modules = glob.glob(os.path.dirname(__file__)+"/*.py")